The conf package reads configurations options in an overriding fashion from a number of sources. In order of importance:
- System level overrides
- Command line arguments
- Environment variables
- A configuration file(s)
- 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 Options
The conf
option 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-keef.json
├── 10-keef.json
└── 30-keef.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-keef.json < 20-keef.json < 30-keef.json
where 20 overrides 10, and 30 overrides 20.
Static File Defaults
To Simplify configuration for deployments, keef
will look for configuration files in fixed locations eliminating the need for run time configuration. File Locations are as follows:
- a file in the rooot of your project with the name
<package.name>
.NODE_ENV
.json
For example, if thename
attribute in your package.json isfoobar
, and the environment varNODE_ENV
is set asproduction
, the file look up isfoobar.production.json
. IfNODE_ENV
is not set, it would befoobar.development.json
- A json file named after your project name in the root of your project -
foobar.json
- A json file named after your project in a
.config
directory in the current users home directory -.config/foobar.json
- A json file named after your project in the
/etc
directory - `/etc/foobar.json
ETCD2 Clusters
For distributed deployments, An etcd2 cluster may be used for configuration purposes. To enable etcd2
configuration loading, 2 environment variables should be set:
etcd__hosts
- A comma separated list ofhost
:port
addresses -etcd1.domain.com:4001,etcd2.domain.com:4001
.etcd__namespace
- a keyspace to keep data separate from everything else.
Any configuration that is stored as object, we be translated into etcd
directories automatically
keef.set('a:b:c', 1)
// Object data
{
"a": {
"b": {
"c": 1
}
}
}
// etc data
/a/b/c 1
System defaults
defaults are what they sound like. Sane defaults for values that are needed to get the application running. They are located in the Defaults module 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 Shorthands module of keef
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
- Since:
-
- 0.1.0
- Source:
Requires
- module:nconf
- module:path
- module:os
- module:debug
- module:fs
- module:keef/lib/shorthands
- module:keef/lib/defaults
- module:keef/lib/overrides