config-load.js
Load config from a tree of JS/JSON files
Current status
Usage
Installation
npm install config-load
Loading
var configLoad = ;
configLoad([path] [, options])
Loads all JS/JSON config files under path, recursively gathering them from the tree structure.
Uses require-folder-tree - see docs for that for explanation of how files are loaded.
If path is not provided, defaults to process.cwd() + '/config'
.
Options
env
Environment type - creates a selector (see below).
Defaults to process.env.NODE_ENV || 'development'
selectors
Object determining what parts of the config object to switch dependent on selectors provided.
Defaults to { env: options.env }
Example
If config file parsing produces:
db: server: 'localhost' database: 'myDB' env: development: db: password: 'dev db password' production: db: password: 'production db password' otherSetting: 'foo'
Then calling:
returns:
db: server: 'localhost' database: 'myDB' password: 'dev db password' otherSetting: 'foo'
null
value
If a selector
's value is null
, it takes the name
key only.
If config file parsing produces:
url: 'http://example.com/' local: url: 'http://mysite.com/'
returns:
url: 'http://mysite.com/'
Tests
Use npm test
to run the tests. Use npm run cover
to check coverage.
Changelog
See changelog.md
Issues
If you discover a bug, please raise an issue on Github. https://github.com/overlookmotel/config-load/issues
Contribution
Pull requests are very welcome. Please:
- ensure all tests pass before submitting PR
- add an entry to changelog
- add tests for new features
- document new functionality/API additions in README