node-env-simple
One function to play with NODE_ENV in various ways.
Install
$ npm install node-env-simple --save
Usage
var env = require('node-env-simple')() /* Get NODE_ENV, default to 'development' if not set */env() // => 'development' /* Set NODE_ENV */env('production') // => 'production'env() // => 'production' /** * Execute function with given NODE_ENV, * with the liberty to restore previous NODE_ENV at any moment */env('test', function (restore) { // process.env.NODE_ENV === 'test' // You can, for example, run a test here restore()}) // => 'production'env() // => 'production' /** * Execute function with context */var context = {foo: 'bar'}env('stage', function (restore) { this.foo // => 'bar' restore()}, context) /** * Async function works too */env('test', function (restore) { asyncTest('a_test', function (err) { restore() })}) env('test', function (restore) { aPromise().then(function () { restore() })}) /** * Or you can designate a environment variable and default value, * a variable 'foo' that defaults to 'bar', for example */var otherEnv = require('node-env-simple')('foo', 'bar')env() // => 'bar'env('par') // => 'par'process.env.foo // => 'par'
Test
$ npm test