envrc
A simple config loader that melds dotenv, rc, and envs.
Features
- 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
Order of paths
In the current directory it looks for
<cwd>/.env.common
<cwd>/.env.default
<cwd>/.env.<NODE_ENV>
<cwd>/.env.local
<cwd>/.env
Then for each of the following directories...
<cwd>
<cwd>/etc
<cwd>/config
<cwd>/.config
...it looks for the following files
common
default
<NODE_ENV>
Usage
Loading
// reads and merges filesvar conf = ; // change your working directoryvar conf = '/some/other/dir';// same asvar conf = cwd: '/some/other/dir'; // override or add some variablesvar conf = NODE_ENV: 'production' foo: 'bar';// same asvar conf = env: NODE_ENV: 'production' foo: 'bar'; // add other lookup directoriesvar conf = dirs: 'my-other-environments';
Values
var conf = buz: 'cool'; // access values as object propertiesconfbuz === 'cool'; // or by calling === 'cool'; // when calling, the second argument value acts as a fallback === 'good save'; // or pass an array as the first argument to fallback to other properties === 'cool';
License
MIT