3

I am deploying a node.js app on heroku. The code looks like this:

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 get Web process failed to bind to $PORT within 60 seconds of launch node.js error. Any help would be appreciated.

std
  • 137
  • 3
  • 12
  • The resolution specified under http://stackoverflow.com/questions/15693192/heroku-node-js-error-web-process-failed-to-bind-to-port-within-60-seconds-of worked for me – user3894746 Jul 31 '14 at 08:25

2 Answers2

5

I would imagine it has something to do with being explicit about the IP address. Try just doing server.listen(port, function() { ... ?

Justin Beckwith
  • 7,686
  • 1
  • 33
  • 55
  • Thanks! You're right. I think heroku tries to listen at url 0.0.0.0 – std Feb 16 '14 at 14:45
  • if anyone has the same problem, for me what sabed was http.createServer(app).listen(process.env.PORT || 3000) (i'm usig express) – user1576978 Mar 05 '14 at 04:19
0

I thought that you're deploying to Heroku. Heroku is assigning a random port to the environment of the application. You can take this random port to your code like this way.

process.env.PORT

My sample code an I've used to do is here:

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

app.listen(config.port, () => {
  logger.info('Listening on port %d', config.port);
});
Kemal Y
  • 59
  • 1
  • 2
  • 6