Setting the port for node.js server on Heroku

Crocodile picture Crocodile · Feb 24, 2015 · Viewed 76k times · Source

I launched a node.js server with the following line to set the port:

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

This means that, it should either read the PORT env variable or default to 8080, as it does when it's run locally. Neither of them is happening on Heroku, and the server always uses the default port 80. Any idea how to change it?

heroku config
PORT: 8080

Answer

punund picture punund · Feb 24, 2015

You can't. Heroku sets the PORT variable that you are supposed to bind, and listens on tcp/80.