npm install envrcA simple config loader that melds dotenv, rc, and envs.
- Loads env files based on common naming conventions and project file structures
- Reads JSON, INI, and YAML
- Combines env configs and environment variables
- Provides property lookup fallbacks and value fallbacks
In the current directory it looks for
-
-
-
-
-
Then for each of the following directories...
-
-
-
-
...it looks for the following files
- common
- default
-
#### Loading
``js
// reads and merges files
var conf = require('envrc')();
// change your working directory
var conf = require('envrc')('/some/other/dir');
// same as
var conf = require('envrc')({cwd: '/some/other/dir'});
// override or add some variables
var conf = require('envrc')({NODE_ENV: 'production', foo: 'bar'});
// same as
var conf = require('envrc')({env: {NODE_ENV: 'production', foo: 'bar'}});
// add other lookup directories
var conf = require('envrc')({dirs: ['my-other-environments']});
`
#### Values
`js
var conf = require('envrc')({buz: 'cool'});
// access values as object properties
conf.buz === 'cool';
// or by calling
conf('buz') === 'cool';
// when calling, the second argument value acts as a fallback
conf('missing', 'good save') === 'good save';
// or pass an array as the first argument to fallback to other properties
conf(['missing', 'buz']) === 'cool';
``
MIT