Environment config file on node.js

Posted in Node.js, on 5/4/2014

Depend on running enviroment, use different configuration files. At node.js world, following module is one of the choice.

Everything is on following link.



1. Basically, what need to be have is, you need to install node-env-file module. 

npm install node-env-file --save

This command will update package.json and install
 node-env-file module. 

2. Create your enviroment file, like .env. The name could be any name. .env_dev, env_prod


3. add following code at node.js server side code. This  will use the  node-env-file module to replace your  process.env.{your variable}.

var env = require('node-env-file');
env(__dirname + '/.env');


When you want to setup the value to empty, you can set the value like this, in this way.


If you code is like following, the will use instead.

process.env.IP || ''