Read environment variables in Node.js
Is there a way to read environment variables in Node.js code?
Like for example Python's
Verified Answer (1863 Votes) ✓
ENV_VARIABLE is the name of the variable you wish to access.
Answer #2 (133 Votes)
When using Node.js, you can retrieve environment variables by key from the
var mode = process.env.NODE_ENV; var apiKey = process.env.apiKey; // '42348901293989849243'
Here is the answer that will explain setting environment variables in node.js
Answer #3 (57 Votes)
If you want to use a string key generated in your Node.js program, say,
var v = 'HOME', you can use
process.env.VARNAME has to be hardcoded in your program.