Can I have node.js listen to a non-standard port when hosted on Heroku?

I am creating a node.js application and experimenting with hosting it on Heroku. It looks like to make my application accessible to the whole world, I need to listen like this:

app.listen(process.env.PORT || 3000);

I want the application to listen on port 8080. Is this possible in Heroku? Can I change the value of process.env.port? It seems to be some kind of reverse proxy that I could not control.

+4
source share
1 answer

No. Heroku tells your application that your application is required to listen. The required interface between Heroku and your application is the PORT environment variable: your application must look for and use it. Your application cannot listen on any port other than the port that Heroku tells your application to listen on. Heroku tries to open a TCP connection with your application on this port, and if sixty seconds have passed since Heroku started the application and your application does not listen on this port, Heroku will report that your application is broken and closes it.

+21
source

All Articles