ez-config
v0.2.1
Published
A simple environment-aware configuration utility exporting clean JS objects
Downloads
23
Maintainers
Readme
EZ Config
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.
Installation
$ npm install ez-config --save
Basic usage
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.
Advanced use
- 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
Tests
I'm checking basic functionality, but coverage is currently disabled due to ES6 limitations in Lab.