Read environment variables in Node.js

前端 未结 6 2072
不知归路
不知归路 2020-11-22 11:41

Is there a way to read environment variables in Node.js code?

Like for example Python\'s os.environ[\'HOME\'].

6条回答
  •  耶瑟儿~
    2020-11-22 12:19

    If you want to use a string key generated in your Node.js program, say, var v = 'HOME', you can use process.env[v].

    Otherwise, process.env.VARNAME has to be hardcoded in your program.

提交回复
热议问题