[Node] Using dotenv to config env variables

Install:

npm install dotenv --save

 

For example, we can store the sensitive information or env related information in a 'veriables.env' file:

// variables.env

NODE_ENV=development
DATABASE=mongodb://xxxxx
MAIL_USER=xx
MAIL_PASS=xx
MAIL_HOST=xxx.io
MAIL_PORT=2525
PORT=7777
MAP_KEY=xxxx
SECRET=xxx
KEY=xxx

 

Then we can use dotenv to load those configurations:

// import environmental variables from our variables.env file
require('dotenv').config({ path: 'variables.env' });

 

Now all the env related information will be stored in:

process.env

 

posted @ 2017-06-07 01:42  Zhentiw  阅读(432)  评论(0编辑  收藏  举报