Setting Environment Variables for Node to retrieve

前端 未结 16 2101
-上瘾入骨i
-上瘾入骨i 2020-11-22 15:41

I\'m trying to follow a tutorial and it says:

There are a few ways to load credentials.

  1. Loaded from environment variables,
16条回答
  •  萌比男神i
    2020-11-22 16:22

    Like ctrlplusb said, I recommend you to use the package dotenv, but another way to do this is creating a js file and requiring it on the first line of your app server.

    env.js:

    process.env.VAR1="Some value"
    process.env.VAR2="Another Value"
    

    app.js:

    require('env')
    console.log(process.env.VAR1) // Some value
    

提交回复
热议问题