How are environment variables retrieved in NodeJS?

2

Suppose I have defined an environment variable in my unix shell with a key, for example:

export DEV_KEY=abcd123abcd123abcd123

How could I access that variable within the code of a NodeJS program? The goal is that the key is not part of the node program code.

    
asked by Pablo Ezequiel 09.03.2017 в 04:22
source

2 answers

4

Through process.env . This property returns an object with all the environment variables of the user or local session:

let key = process.env.DEV_KEY;
    
answered by 09.03.2017 / 05:09
source
1

To complement the answer, also say that you can use the array notation process.env['FOO']

    
answered by 10.03.2017 в 00:25