config-getter
Simple json configuration reader with file and env variables overrides. Can fetch / override variables using:
- Local file
- Env variables
- Consul key-value
For 0.0.x versions documentation see older README.md
Installation
$ npm install config-getter
Usage
default.js
moduleexports = "db": "host": "localhost" "port": "12345"
overrides.json
"db": "host": "google.com"
app.js
const getConfig = getConfig; //// Obtain final configuration object.//// Important Notice: even that underlying fetchers use async IO,// interface to getConfig is sync for usability purposes. // As a result, Application that use config-getter should do getConfig once at startup time.//let config = ; console;
Simple config loading
$ node app.js
Override config with overrides.json values
$ PATH_TO_CONFIG=./overrides.json node app.js
Override config with overrides.json values and single key value
$ PATH_TO_CONFIG=./overrides.json CONFIG_db_port=7777 node app.js
Placeholders
It's possible to make a reference to previous defined value in some config string value:
So phrase will become "hello, world!". It is possbile to make reference in inner objects too:
"$(some.obj.value)"
Placeholders also may be relative. Currently the same level, and parent level are supported.
"a": "a1": "name": "Vasya" "phrase": "My name is $(.name)" // link to the same level var starts with single dot '.' "a2": "name": "$(..a1.name)" // link to upper level var starts with two dots '..'
Tests
$ sudo npm install nodeunit -g$ npm test
Author
License
MIT