Read environment variables in Node.js

前端 未结 6 2008
不知归路
不知归路 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:31

    When using Node.js, you can retrieve environment variables by key from the process.env object:

    for example

    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

提交回复
热议问题