Getting “Application Error” while deploying my Node.js app using “heroku open”

Multi tool use
Getting “Application Error” while deploying my Node.js app using “heroku open”
I made a project, specifically, a URL Shortener using Node.js which runs perfectly when run locally on a port. However, while trying to push it via Heroku using heroku open
command I got this error:
heroku open
Application error
An error occurred in the application and your page could not be served. If you
are the application owner, check your logs for details.
After checking my logs using command heroku logs
, I got
heroku logs
2018-06-30T12:12:49.803878+00:00 heroku[web.1]: Error R10 (Boot timeout) ->
Web process failed to bind to $PORT within 60 seconds of launch
2018-06-30T12:12:49.803878+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-06-30T12:12:49.863059+00:00 heroku[web.1]: Process exited with status
137
2018-06-30T12:12:49.917775+00:00 heroku[web.1]: State changed from starting
to crashed
2018-06-30T12:12:50.752040+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=maan-singh.herokuapp.com
request_id=3c9d005b-1d44-4dd6-949f-e8569d11d6ce fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:12:53.135532+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com
request_id=5831725a-1741-4de2-b584-1e93781acbb3 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:15:06.131305+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=maan-singh.herokuapp.com
request_id=52a81f50-a39a-447c-b5ff-6762306f6a30 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:15:07.638452+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com
request_id=1442fbc5-b1c4-48d8-aaaa-b0d077a3c599 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:17:18.615544+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=maan-singh.herokuapp.com
request_id=e7174a54-81d7-41ad-be32-b24bdcc81058 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:17:20.204337+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com
request_id=31beadca-550e-4465-9248-bbf249a3a3e5 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:19:59.481276+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=maan-singh.herokuapp.com
request_id=279bf7fa-620d-4f7f-a8df-1aed11b8e743 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:20:00.925705+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com
request_id=f256ddc2-b25a-4e33-a286-e56ba883cdf0 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:22:32.739228+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=maan-singh.herokuapp.com
request_id=293c6632-7858-4cee-b027-bb9ac410dbf3 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:22:34.218261+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com
request_id=d278275d-890a-4941-a7ad-1426d384369d fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:25:29.680329+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=maan-singh.herokuapp.com
request_id=c9c822d5-c0d0-4102-86f3-7cd25125056e fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:25:31.217264+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com
request_id=797ff435-7bdb-4db7-83a7-8df3cf5c2c73 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:30:43.275158+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=maan-singh.herokuapp.com
request_id=988205da-18c6-4c0a-be94-74d3f0b9f580 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:30:44.718764+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com
request_id=609ade39-ce5a-4099-bd7a-99ea7fe6acff fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:32:34.854123+00:00 heroku[web.1]: State changed from crashed to
down
2018-06-30T12:32:34.732293+00:00 app[api]: Scaled to web@0:Free by user
maan.vs97@gmail.com
2018-06-30T12:33:16.888301+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=maan-singh.herokuapp.com
request_id=3aa3ccc4-796d-4abb-bf21-85806f2f1419 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:33:18.353601+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com
request_id=10fd0f3a-4301-405e-a0c9-ec64bcb5142d fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:33:49.923844+00:00 app[api]: Scaled to web@1:Free by user
maan.vs97@gmail.com
2018-06-30T12:33:52.699604+00:00 heroku[web.1]: Starting process with command
`node app.js`
2018-06-30T12:33:55.925804+00:00 app[web.1]: You are listening to port 3000
2018-06-30T12:33:55.980456+00:00 app[web.1]: (node:4)
UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to
server [localhost:27017] on first connect [MongoNetworkError: connect
ECONNREFUSED 127.0.0.1:27017]
2018-06-30T12:33:55.980460+00:00 app[web.1]: at Pool.<anonymous>
(/app/node_modules/mongodb-core/lib/topologies/server.js:505:11)
2018-06-30T12:33:55.980463+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:33:55.980464+00:00 app[web.1]: at Pool.emit (events.js:211:7)
2018-06-30T12:33:55.980468+00:00 app[web.1]: at Object.onceWrapper
(events.js:317:30)
2018-06-30T12:33:55.980466+00:00 app[web.1]: at Connection.<anonymous>
(/app/node_modules/mongodb-core/lib/connection/pool.js:329:12)
2018-06-30T12:33:55.980469+00:00 app[web.1]: at emitTwo (events.js:126:13)
2018-06-30T12:33:55.980471+00:00 app[web.1]: at Connection.emit
(events.js:214:7)
2018-06-30T12:33:55.980473+00:00 app[web.1]: at Socket.<anonymous>
(/app/node_modules/mongodb-core/lib/connection/connection.js:245:50)
2018-06-30T12:33:55.980474+00:00 app[web.1]: at Object.onceWrapper
(events.js:315:30)
2018-06-30T12:33:55.980476+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:33:55.980477+00:00 app[web.1]: at Socket.emit (events.js:211:7)
2018-06-30T12:33:55.980480+00:00 app[web.1]: at emitErrorNT
(internal/streams/destroy.js:64:8)
2018-06-30T12:33:55.980482+00:00 app[web.1]: at _combinedTickCallback
(internal/process/next_tick.js:138:11)
2018-06-30T12:33:55.980483+00:00 app[web.1]: at process._tickCallback
(internal/process/next_tick.js:180:9)
2018-06-30T12:33:55.981085+00:00 app[web.1]: (node:4)
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error
originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch().
(rejection id: 1)
2018-06-30T12:33:55.981260+00:00 app[web.1]: (node:4) [DEP0018]
DeprecationWarning: Unhandled promise rejections are deprecated. In the
future, promise rejections that are not handled will terminate the Node.js
process with a non-zero exit code.
2018-06-30T12:34:52.721215+00:00 heroku[web.1]: Error R10 (Boot timeout) ->
Web process failed to bind to $PORT within 60 seconds of launch
2018-06-30T12:34:52.721306+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-06-30T12:34:52.860272+00:00 heroku[web.1]: State changed from starting
to crashed
2018-06-30T12:34:52.863587+00:00 heroku[web.1]: State changed from crashed to
starting
2018-06-30T12:34:52.841500+00:00 heroku[web.1]: Process exited with status
137
2018-06-30T12:34:54.755270+00:00 heroku[web.1]: Starting process with command
`node app.js`
2018-06-30T12:34:56.835821+00:00 app[web.1]: You are listening to port 3000
2018-06-30T12:34:56.863257+00:00 app[web.1]: (node:4)
UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to
server [localhost:27017] on first connect [MongoNetworkError: connect
ECONNREFUSED 127.0.0.1:27017]
2018-06-30T12:34:56.863262+00:00 app[web.1]: at Pool.<anonymous>
(/app/node_modules/mongodb-core/lib/topologies/server.js:505:11)
2018-06-30T12:34:56.863264+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:34:56.863265+00:00 app[web.1]: at Pool.emit (events.js:211:7)
2018-06-30T12:34:56.863266+00:00 app[web.1]: at Connection.<anonymous>
(/app/node_modules/mongodb-core/lib/connection/pool.js:329:12)
2018-06-30T12:34:56.863267+00:00 app[web.1]: at Object.onceWrapper
(events.js:317:30)
2018-06-30T12:34:56.863268+00:00 app[web.1]: at emitTwo (events.js:126:13)
2018-06-30T12:34:56.863269+00:00 app[web.1]: at Connection.emit
(events.js:214:7)
2018-06-30T12:34:56.863271+00:00 app[web.1]: at Socket.<anonymous>
(/app/node_modules/mongodb-core/lib/connection/connection.js:245:50)
2018-06-30T12:34:56.863272+00:00 app[web.1]: at Object.onceWrapper
(events.js:315:30)
2018-06-30T12:34:56.863273+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:34:56.863274+00:00 app[web.1]: at Socket.emit (events.js:211:7)
2018-06-30T12:34:56.863275+00:00 app[web.1]: at emitErrorNT
(internal/streams/destroy.js:64:8)
2018-06-30T12:34:56.863277+00:00 app[web.1]: at _combinedTickCallback
(internal/process/next_tick.js:138:11)
2018-06-30T12:34:56.863278+00:00 app[web.1]: at process._tickCallback
(internal/process/next_tick.js:180:9)
2018-06-30T12:34:56.863324+00:00 app[web.1]: (node:4)
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error
originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch().
(rejection id: 1)
2018-06-30T12:34:56.863396+00:00 app[web.1]: (node:4) [DEP0018]
DeprecationWarning: Unhandled promise rejections are deprecated. In the
future, promise rejections that are not handled will terminate the Node.js
process with a non-zero exit code.
2018-06-30T12:35:11.726745+00:00 heroku[router]: at=error code=H20 desc="App
boot timeout" method=GET path="/" host=maan-singh.herokuapp.com
request_id=68e14a23-255a-4c6d-99d6-525727a2b800 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:35:55.215653+00:00 heroku[web.1]: Error R10 (Boot timeout) ->
Web process failed to bind to $PORT within 60 seconds of launch
2018-06-30T12:35:55.215699+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-06-30T12:35:55.296657+00:00 heroku[web.1]: Process exited with status
137
2018-06-30T12:35:55.314683+00:00 heroku[web.1]: State changed from starting
to crashed
2018-06-30T12:35:56.892537+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=maan-singh.herokuapp.com
request_id=e9ed60ed-3dc5-42a8-86d8-e60942c803f5 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:36:01.869896+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=maan-singh.herokuapp.com
request_id=cd84ae69-d3c2-4ab1-892b-4dc933048c77 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:36:03.805047+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com
request_id=b9455320-0f8e-4d28-8793-612d47635954 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T12:58:34.550597+00:00 heroku[web.1]: State changed from crashed to
starting
2018-06-30T12:58:36.492786+00:00 heroku[web.1]: Starting process with command
`node app.js`
2018-06-30T12:58:38.568708+00:00 app[web.1]: You are listening to port 3000
2018-06-30T12:58:38.590986+00:00 app[web.1]: (node:4)
UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to
server [localhost:27017] on first connect [MongoNetworkError: connect
ECONNREFUSED 127.0.0.1:27017]
2018-06-30T12:58:38.590989+00:00 app[web.1]: at Pool.<anonymous>
(/app/node_modules/mongodb-core/lib/topologies/server.js:505:11)
2018-06-30T12:58:38.590991+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:58:38.590992+00:00 app[web.1]: at Pool.emit (events.js:211:7)
2018-06-30T12:58:38.590993+00:00 app[web.1]: at Connection.<anonymous>
(/app/node_modules/mongodb-core/lib/connection/pool.js:329:12)
2018-06-30T12:58:38.590994+00:00 app[web.1]: at Object.onceWrapper
(events.js:317:30)
2018-06-30T12:58:38.590995+00:00 app[web.1]: at emitTwo (events.js:126:13)
2018-06-30T12:58:38.590996+00:00 app[web.1]: at Connection.emit
(events.js:214:7)
2018-06-30T12:58:38.590997+00:00 app[web.1]: at Socket.<anonymous>
(/app/node_modules/mongodb-core/lib/connection/connection.js:245:50)
2018-06-30T12:58:38.590999+00:00 app[web.1]: at Object.onceWrapper
(events.js:315:30)
2018-06-30T12:58:38.591000+00:00 app[web.1]: at emitOne (events.js:116:13)
2018-06-30T12:58:38.591001+00:00 app[web.1]: at Socket.emit (events.js:211:7)
2018-06-30T12:58:38.591015+00:00 app[web.1]: at emitErrorNT
(internal/streams/destroy.js:64:8)
2018-06-30T12:58:38.591017+00:00 app[web.1]: at _combinedTickCallback
(internal/process/next_tick.js:138:11)
2018-06-30T12:58:38.591018+00:00 app[web.1]: at process._tickCallback
(internal/process/next_tick.js:180:9)
2018-06-30T12:58:38.591063+00:00 app[web.1]: (node:4)
UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error
originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch().
(rejection id: 1)
2018-06-30T12:58:38.591132+00:00 app[web.1]: (node:4) [DEP0018]
DeprecationWarning: Unhandled promise rejections are deprecated. In the
future, promise rejections that are not handled will terminate the Node.js
process with a non-zero exit code.
2018-06-30T12:59:37.052499+00:00 heroku[web.1]: Error R10 (Boot timeout) ->
Web process failed to bind to $PORT within 60 seconds of launch
2018-06-30T12:59:37.052596+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-06-30T12:59:37.173301+00:00 heroku[web.1]: State changed from starting
to crashed
2018-06-30T12:59:37.139128+00:00 heroku[web.1]: Process exited with status
137
2018-06-30T13:00:15.376173+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/" host=maan-singh.herokuapp.com
request_id=5449c1e7-e849-4192-a691-7a7c1e71f530 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
2018-06-30T13:00:17.426839+00:00 heroku[router]: at=error code=H10 desc="App
crashed" method=GET path="/favicon.ico" host=maan-singh.herokuapp.com
request_id=5b02acc8-7218-4bd3-8c3a-a8183000c363 fwd="103.47.59.2" dyno=
connect= service= status=503 bytes= protocol=https
The link address of my app is https://maan-singh.herokuapp.com/
I used a local MongoDB databse project and even tried to push the project using heroku open
command with and without starting MongoDB from my command prompt but to no use. In this, I did not use a GitHub repository to push my code as I already had the files in my computer. Is that the reason for the error?
heroku open
Please let me know any more information is needed. Thank you.
1 Answer
1
Web process failed to bind to $PORT within
The error you are getting generally means you have assigned a hardcoded port in your main or index node js file. This is causing the Heroku to crash as Heroku tries to allocate a random port of its choice to your node application on startup. Thus your application is not able to start.
To fix this you will have to set the port for you node application like below.
const PORT = process.env.PORT || 3000;
...
...
.listen(PORT); // START YOUR SERVER HERE
This will allow your node app to be served on port 3000 when you run it locally and when you push this code to Heroku, it will assign a random port available fixing the error.
can you post some code please.
– damitj07
2 days ago
Here's my app.js code:
var express = require('express'); var urlShortenerController = require('./controllers/urlShortenerController'); var bodyParser = require('body-parser'); var mongoose = require('mongoose'); var config = require('./config'); var base58 = require('./base58'); var app = express(); app.set('port', (process.env.PORT || 3000)); var Url = require('./models/url'); mongoose.connect('mongodb://' + config.db.host + '/' + config.db.name, {autoIndex: false});
– Maan V. Singh
yesterday
var express = require('express'); var urlShortenerController = require('./controllers/urlShortenerController'); var bodyParser = require('body-parser'); var mongoose = require('mongoose'); var config = require('./config'); var base58 = require('./base58'); var app = express(); app.set('port', (process.env.PORT || 3000)); var Url = require('./models/url'); mongoose.connect('mongodb://' + config.db.host + '/' + config.db.name, {autoIndex: false});
var urlencodedParser = bodyParser.urlencoded({ extended: false }); app.set('view engine', 'ejs'); app.use(express.static('assets')); app.get('/moesurl', function(req, res){ // route to serve up the homepage (index.html) res.sendFile('index.html', {root: './'}); }); app.post('/moesurl', urlencodedParser, function(req, res){ console.log(req.body); var urlLong = req.body.inputurl; var urlShort = ''; // the shortened URL we will return var urlPrefix = urlLong.substring(0,5);
– Maan V. Singh
yesterday
var urlencodedParser = bodyParser.urlencoded({ extended: false }); app.set('view engine', 'ejs'); app.use(express.static('assets')); app.get('/moesurl', function(req, res){ // route to serve up the homepage (index.html) res.sendFile('index.html', {root: './'}); }); app.post('/moesurl', urlencodedParser, function(req, res){ console.log(req.body); var urlLong = req.body.inputurl; var urlShort = ''; // the shortened URL we will return var urlPrefix = urlLong.substring(0,5);
if (urlPrefix === "https" || urlPrefix === "http:"){ urlLong = urlLong; } else { urlLong = "http://" + urlLong; } if (urlLong.length >= 2000) { res.render('error'); } else { // check if url already exists in database Url.findOne({long_url: urlLong}, function(err, doc){ if (doc){ // URL has already been shortened // base 58 encode the unique _id of that document and construct the short URL urlShort = config.webhost + base58.encode(doc._id); res.render('next', {data2: urlShort});
– Maan V. Singh
yesterday
if (urlPrefix === "https" || urlPrefix === "http:"){ urlLong = urlLong; } else { urlLong = "http://" + urlLong; } if (urlLong.length >= 2000) { res.render('error'); } else { // check if url already exists in database Url.findOne({long_url: urlLong}, function(err, doc){ if (doc){ // URL has already been shortened // base 58 encode the unique _id of that document and construct the short URL urlShort = config.webhost + base58.encode(doc._id); res.render('next', {data2: urlShort});
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I already have that taken care of in my code. I have 'process.env.PORT || 3000' in my code
– Maan V. Singh
Jul 1 at 17:03