Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the port for node.js server on Heroku

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 
like image 954
Crocodile Avatar asked Feb 24 '15 21:02

Crocodile


People also ask

How do I specify a heroku PORT?

Heroku expects a web application to bind its HTTP server to the port defined by the $PORT environment variable. Many frameworks default to port 8080, but can be configured to use an environment variable instead.

What PORT does node js server use?

The default port for HTTP is 80 – Generally, most web browsers listen to the default port. Below is the code implementation for creating a server in node and making it listen to port 80.


1 Answers

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

like image 134
punund Avatar answered Sep 22 '22 00:09

punund