A simple configuration file loader for node.js following some of the basic
style of node-config, but with a
focus on simplicity. It supports js
, json
, and yaml
configuration files,
as well as environmental overrides.
$ npm install ez-config --save
Create a config
directory at the root of your app and place a default.json
with the following contents:
{
"demo": {
"rad": "cool"
}
}
Then do this:
var config = require("ez-config");
config.get();
// { "demo": { "rad": "cool" } }
config.get("demo.rad");
// "cool"
config.get("nothing.real");
// undefined (not a thrown error)
Notice that get
accepts hoek.reach
-style
paths, and will return undefined if they do not exist.
- Obeys the import hierarchy described here.
- Allows setting the
NODE_CONFIG_DIR
environment variable to something other thanconfig
. - Allows an environmental override via JSON string, e.g.
NODE_CONFIG='{"demo":"foo"}' node app.js
- Allows a command-line override via JSON string, e.g.
node app.js --NODE_CONFIG='{"demo":"foo"}'
- You can include the ES6 code if that's useful, with
require("ez-config/es6")
-- the Object.assign polyfill will not be loaded
I'm checking basic functionality, but coverage is currently disabled due to ES6 limitations in Lab.