I am trying to prepare my app for production on a ubuntu running nginx. I have been using the dotenv npm package during development, but need a more stable and secure method for production. I have added the variables to /etc/environment because I would like them to exist in the app permanently.

Can someone explain to me how to access them from my server.js file?

I have tried using process.env.variable and $variable but neither seem to work.


Simply: source /etc/environment

Now run your application from the same shell, and process.env.foo should pick up the foo variable if it was declared in your env file.

You may also try running the application in a docker container and the docker-run command has an option --env-file=... where you can supply an environment file such as /etc/environment.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.