The web process failed to bind to $ PORT within 60 seconds after starting node.js

I am deploying a node.js application on heroku. The code is as follows:

var port = process.env.PORT || 8080;
var ip_addr = "127.0.0.1";
server.listen(port, ip_addr, function() {
    console.log("%s listening at %s ", server.name, server.url);
});

I don’t know why I am causing the web process to not contact $ PORT for 60 seconds after the node.js launch error. Any help would be appreciated.

+3
source share
2 answers

I would suggest that this has something to do with being explicit about the IP address. Try simply running server.listen (port, function () {...?

+4
source

I thought you were going to Heroku. Heroku assigns a random port to the application environment. You can take this random port to your code, like this one.

process.env.PORT

My sample code that I used is here:

// production
config.port = process.env.PORT

app.listen(config.port, () => {
  logger.info('Listening on port %d', config.port);
});
0

All Articles