Conner Frey Conner Frey - 4 months ago 35x
Node.js Question

Port Timeout With NodeJS/Webpack Heroku Deployment

Note: Everything works perfectly on my localhost environment. When I

git push heroku master
I get a successful push/deploy. I check the Heroku Logs and I see this error:

[]: Stopping process with SIGKILL
[]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 120 seconds of launch

I have read many posts regarding this issue and the fix that I see is

app.set('port', (process.env.PORT || 4000));

This is not my fix since I am already doing this in my server code. Here is my server code:

var path = require('path');
var express = require('express');

var app = express();
app.set('port', (process.env.PORT || 4000));

app.use(express.static(__dirname + '/public'));
app.get('*', function response(req, res) {
res.render(path.join(__dirname, 'public/index.html'));

app.listen(app.get('port'), 'localhost', function onStart(err) {
if (err) {
}'==> Listening on port %s.', app.get('port'));

NOTE: In the Heroku logs,
==> Listening on port %s.
is printed and THEN the timeout happens after that (with no error). So it does get to the end of my server code without error and it prints the correct, random Heroku port.

webpack -p
also creates my
correctly too.

has these two commands and they are executed without error:

"start": "NODE_ENV=production webpack -p && node server",
"postinstall": "bower install --force"

I am truly at a loss. Please help!

EDIT: I believe I have truly isolated the problem to my
file. I ended up doing
webpack -p
and pushed up the
file––essentially bypassing webpack on Heroku. I then do the simple
npm start
command (which is essentially just
node server.js
command) and my app still times out when trying to connect to the port.


WOW I figured it out. I had this line in my server:

app.listen(app.get('port'), 'localhost', function onStart(err) .... I just needed to remove 'localhost' from the listen() function.