oniyi-config
Simple config file loader
Installation
$ npm install --save oniyi-config
Usage
const oniyiConfig = ; const cfg = ;
will merge js
and json
files starting with name providers
in __dirname
iteratively. File name schema is providers.[environment].(json|js)
.
environment
is optional and defaults to development
. Possible values are anything you can set in process.env.NODE_ENV
. For file name resolution, process.env.NODE_ENV
will be transformed to lower-case.
One special environment is local
. It will always be loaded last. You can provide the same file name with different extensions. json
will always be loaded before js
, meaning js
will overwrite json
Sample load order:
- providers.json
- providers.js
- providers.development.json
- providers.development.js
- providers.local.json
- providers.local.js
Options
- sourceDir, baseDir, basePath: single directory path to load config files from
- sourceDirs: array of directory paths to load config files from. Files are loaded in preceding order (meaning the last one is loaded first extended with
_.mergeWith()
in reverse order; ascustomizer
for_.mergeWith()
, a custom function fromlib/utils.js
is used) - baseName: the baseName for config files (e.g.
providers
from the example above) - env, environment: the
environment
part of config file names (e.g.development
from the example above) Note:local
is always added / loaded
License
MIT © Benjamin Kroeger