I'd like to change the value of process.env.PORT
, how can I do this?
I'm running Ubuntu 12.04.
This question is related to
node.js
environment-variables
use the below command to set the port number in node process while running node JS programme:
set PORT =3000 && node file_name.js
The set port can be accessed in the code as
process.env.PORT
You can use cross platform solution https://www.npmjs.com/package/cross-env
$ cross-env PORT=1234
EDIT: Per @sshow's comment, if you're trying to run your node app on port 80, the below is not the best way to do it. Here's a better answer: How do I run Node.js on port 80?
Original Answer:
If you want to do this to run on port 80 (or want to set the env variable more permanently),
vim ~/.bash_profile
export PORT=80
sudo visudo
Defaults env_keep +="PORT"
Now when you run sudo node app.js
it should work as desired.
Source: Stackoverflow.com