keef

5.0.0 • Public • Published

keef

Codeship Status for megadoomer/keef

Multi tier configuration loader as a package

The conf package reads configurations options in an overriding fashion from a number of sources. In order of importance:

  1. System level overrides
  2. Command line arguments
  3. Environment variables
  4. A configuration file(s)
  5. Data loaded from an ETCD2 backend if specified
  6. System specified defaults

Overrides

Overrides can not be overriden or changed at any point in time. The are defined in conf/lib/overrides.js and should be reserved for static run time properties. Conf serves as a central place to get that information.

For example, the full path to the packages directory is resolved at run time and loaded in to the conf loader. It won't / can't change during run time, but may change in the future. By getting the information from conf, application logic does not need to change between restarts or releases.

If overrides need to be change or added the overrides.js file must be changed

Command Line Arguments

Command line arguments are the highest level of maliable values. The can be used to set specific and nested values in the configuration JSON document but using a : spearator between keys. For example, using the flag: --foo:bar=1, would create an object like

{
    "foo":{
        "bar": 1
    }
}

Environment Variables

Environment variables work much the same as command line arguments. However, most bash implenetations don't read :'s very well, so the double underscore ( __ ) is used in its place foo__bar=1 npm start

{
    "foo":{
        "bar": 1
    }
}

Conf File

The conf options can be set to read specific configuration from a file(s). The value should be a full path. If the path points to a directory, the conf loader will read all json files, sort them and load their values in an overriding order. Sorting is done in a descending, lexigraphical order.

└── conf
    ├── 20-second.json
    ├── 10-first.json
    └── 30-third.json

Given the above directory of conf files, the server can be configured by pointing the conf arguments at the directory

node server --conf=$HOME/conf

The configruation would be read in the following priority 10-first.json < 20-second.json < 30-third.json

where 20 overrides 10, and 30 overrides 20.

System defaults

defaults are what they sound like. Sane defaults for values that are needed to get the application running. They are located in conf/lib/defaults.js and are used only as fallback values.

Option Shorthands

Top level options can be aliased. Short hand aliases can be found and defined in the lib/shorthands.js module.

Flag Shorthand Description
PORT p Specifies the port the server will bind to
logger l specify the type(s) of logging transports for the server to use

the following invocations are treated the same

node server --PORT=3001 --logger=stdout --logger=file
PORT=3001 logger=stdout nodeserver -l file
node server -p 3001 -l stdout -l file

Package Sidebar

Install

npm i keef

Weekly Downloads

3

Version

5.0.0

License

MIT

Unpacked Size

15.6 kB

Total Files

6

Last publish

Collaborators

  • esatterwhite