I'm running a node app created with create-react-app. I wanted to make it run on port 80, so I added a .env file with the contents
PORT=80
When I run npm start, I get
? Admin permissions are required to run a server on a port below 1024.
but when I run sudo npm start, the app starts on port 3000.
Why does my .env file get ignored when I run with sudo, and how can I fix this?
EDIT: This question is not about how to keep my current environment variables when I run sudo. This question is about the behavior of .env, and why it doesn't work when running with sudo.
Interestingly, when I use su, eg.
$ su
# npm start
It runs on port 80.
To be entirely clear, I would like to know how I can run my app on port 80 without passing the port in the command, i.e. sudo PORT=80 npm start.
I believe this is the whole point of .env, hence the question.
 
    