How to change value of process.env.PORT in node.js?


Question

I'd like to change the value of process.env.PORT, how can I do this?

I'm running Ubuntu 12.04.

1
131
6/30/2015 7:20:58 PM

Accepted Answer

For just one run (from the unix shell prompt):

$ PORT=1234 node app.js

More permanently:

$ export PORT=1234
$ node app.js

In Windows:

set PORT=1234

In Windows PowerShell:

$env:PORT = 1234
264
1/28/2014 9:04:27 PM

You can use cross platform solution https://www.npmjs.com/package/cross-env

$ cross-env PORT=1234

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon