2

I successfully have my app running on foreman start perfectly well, but as soon as I deploy it to Heroku, it throws me an error in the logs:

2012-08-20T03:22:48+00:00 heroku[web.1]: Starting process with command `node index.js`
2012-08-20T03:22:49+00:00 app[web.1]: Server has started.
2012-08-20T03:22:49+00:00 heroku[web.1]: Error R11 (Bad bind) -> Process bound to port 15134, should be 52717 (see environment variable PORT)
2012-08-20T03:22:49+00:00 heroku[web.1]: Stopping process with SIGKILL
2012-08-20T03:22:51+00:00 heroku[web.1]: Process exited with status 137
2012-08-20T03:22:51+00:00 heroku[web.1]: State changed from starting to crashed

I have tried to change which port it binds to, but every time I do it changes the port again. Is there something else wrong in my app?

Brad Ross
  • 451
  • 8
  • 26
  • Are you trying to hardcode the port? Heroku is going to want to bind to a different port every time. Your Procfile should be using the `$PORT` variable, if it isn't already. – numbers1311407 Aug 20 '12 at 03:58
  • I should try that. Does Node.js support it? – Brad Ross Aug 20 '12 at 04:07
  • Heroku will set the `PORT` environment variable, which is what you want to use. This might help you: http://stackoverflow.com/questions/7503632/node-js-port-issue-on-heroku-cedar-stack – numbers1311407 Aug 20 '12 at 04:14
  • Nope. Doesn't work, just says "$PORT" is not defined – Brad Ross Aug 20 '12 at 04:16
  • I am using Vanilla Node.js, no Express or any other framework – Brad Ross Aug 20 '12 at 04:17
  • Check out the link. node doesn't take the port as a command line argument (wouldn't make sense for node) but rather uses the PORT environment variable (`process.env.PORT` in node). That's the port you have to bind to. It's accessible via `$PORT` in the Procfile, but that's actually not useful to you in node (disregard the first comment). – numbers1311407 Aug 20 '12 at 04:19
  • Thanks! Works so well, the process.env.PORT! Thank you so much! – Brad Ross Aug 20 '12 at 04:21

1 Answers1

6

on Heroku, you need to use the port contained in an environment variable: process.env.PORT

Rotem Harel
  • 736
  • 8
  • 16