NODE-ENV-FILE
Parse and load environment files (containing ENV variable exports) into Node.js environment, i.e. process.env
.
Example
.env
FOO=foo1
BAR=bar1
BAZ=1
QUX=
.env2
exports FOO=foo2
exports BAR=bar2
exports BAZ=2
exports QUX=
index.js
var assert = require('assert');
var env = require('node-env-file');
process.env.FOO = "defaultfoo";
env(__dirname + '/.env');
assert.equal(process.env.FOO, "defaultfoo");
assert.equal(process.env.BAR, "bar1");
assert.equal(process.env.BAZ, "1");
assert.equal(process.env.QUX, "");
assert.equal(process.env.QUUX, undefined);
env(__dirname + '/.env2', {overwrite: true});
assert.equal(process.env.FOO, "foo2");
assert.equal(process.env.BAR, "bar2");
assert.equal(process.env.BAZ, "2");
assert.equal(process.env.QUX, "");
assert.equal(process.env.QUUX, undefined);
API
-
(filepath)
env('./path/to/.env');
-
(filepath, options)
env('./path/to/.env', {verbose: true, overwrite: true, raise: false, logger: console});
Installation
$ npm install node-env-file
Test
Local tests:
$ make test
Examples
Local examples:
$ make example
Related Libraries
License
Released under the MIT license.
Copyright (c) Jonas Grimfelt