I’m using node.js on EC2
I type
EXPORT PORT=80
in terminal, and i see that it correctly saves it when i type EXPORT
But when I run my node.js app with the following:
...
console.log(process.env);
...
PORT is not listed in the object when I’m running it with sudo:
sudo node app.js
How do I set PORT so that I can access it from the process.env object while running node with sudo?
To set
process.envvariable use the following code:Of course, you can set multiple
process.envvariables:Normally,
EXPORTshould work too. Butsudocreates its own environments and then starts your program asroot. So, you shall either addPORTtosudo‘s environment or force it to preserve your own environment.To change
sudo‘s environment you shall modify/root/.profile.To force it to preserve your own environment use
-Ekey: