Skip to content

A simple environment-aware configuration utility for node.js, exporting clean JS objects.

License

Notifications You must be signed in to change notification settings

mshick/ez-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

npm release

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 than config.
  • 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.

About

A simple environment-aware configuration utility for node.js, exporting clean JS objects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published