https://github.com/grimen/node-env-file
Parse and load environment files (containing ENV variable exports) into Node.js environment, i.e. `process.env`.
https://github.com/grimen/node-env-file
Last synced: about 2 months ago
JSON representation
Parse and load environment files (containing ENV variable exports) into Node.js environment, i.e. `process.env`.
- Host: GitHub
- URL: https://github.com/grimen/node-env-file
- Owner: grimen
- License: mit
- Created: 2013-09-28T20:34:10.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-04-15T04:09:57.000Z (about 8 years ago)
- Last Synced: 2025-03-31T10:06:41.641Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://npmjs.org/package/node-env-file
- Size: 33.2 KB
- Stars: 119
- Watchers: 4
- Forks: 18
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# NODE-ENV-FILE [](http://travis-ci.org/grimen/node-env-file)
Parse and load environment files (containing ENV variable exports) into Node.js environment, i.e. `process.env`.
## Example
**`.env`**
```bash
# some env variablesFOO=foo1
BAR=bar1
BAZ=1
QUX=
# QUUX=
```**`.env2`**
```bash
# some env variables using exports syntaxexports FOO=foo2
exports BAR=bar2
exports BAZ=2
exports QUX=
# exports QUUX=```
**`index.js`**
```javascript
var assert = require('assert');
var env = require('node-env-file');process.env.FOO = "defaultfoo";
// Load any undefined ENV variables from a specified file.
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);// Load another ENV file - and overwrite any defined ENV variables.
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);
// Load any undefined ENV variables from a specified file, but don't crash if the file doesn't exist
// Usefull for testing env vars in development, but using "real" env vars in production
envfile(__dirname + '/.env', {raise: false});
```## API
* `(filepath)`
```javascript
env('./path/to/.env');
```* `(filepath, options)`
```javascript
env('./path/to/.env', {verbose: true, overwrite: true, raise: false, logger: console});
```## Installation
```shell
$ npm install node-env-file
```## Test
**Local tests:**
```shell
$ make test
```## Examples
**Local examples:**
```shell
$ make example
```## Related Libraries
* **[node-env-flag](http://github.com/grimen/node-env-flag)**
## License
Released under the MIT license.
Copyright (c) [Jonas Grimfelt](http://github.com/grimen)
[](https://bitdeli.com/free "Bitdeli Badge")