javascript tutorial - [Solved-3 Solutions] Read environment variables in Node.js - javascript - java script - javascript array
Problem:
How to read environment variables in Node.js?
Solution 1:
Where ENV_VARIABLE
is the name of the variable
Solution 2:
- using Node.js , you can retrieve environment variables by key from the
process.env
object: - for example
Solution 3:
want to use a string key generated in your Node.js program, say, var v = 'HOME'
, we can use process.env[v]
.
Otherwise, process.env.VARNAME
has to be hardcoded