0.1.0 • Published 10 years ago
l6conf v0.1.0
l6conf
Overview
This node.js library introduces a policy for transforming environment variables into a hierarchically structured json and allows you to overwrite configurations by importing multiple config files consequently.
Overwriting Example
The overwrite direction goes from right to left, each new setting value overwrites previous ones.
/*
Environment variables:
FOO=0
*/
config.json({ "foo": "1", "bar": "2", "lorem": "ipsum" }).json({ "bar": "3" }).env();
config.get("foo"); // 0
config.get("bar"); // 3
config.get("lorem"); // ipsumNesting Example
DATABASE="MySpecialDB"
DATABASE_USERNAME="root"
DATABASE_PASSWORD="test"transforms to:
config.get('database'); // MySpecialDB
config.get('database.username'); // root
config.get('database.password'); // testDocumentation
Installation
$ npm i --save l6confLoad
let config = require('l6conf');Set Environment variables
/*
process.env.USER = "test"
process.env.USER_FIRSTNAME = "John"
process.env.USER_PASSWORD = "so_secret"
*/
// Sets the variables
config.env();
/*
config.get('user'); // test
config.get('user.firstname'); // John
config.get('user.password') // so_secret
*/Set JSON variables
config.json('./path/to/file.json');or
config.json({ "hello": { "world": "I am json" } });Set custom variables
config.set('foo', 'bar');or
config.json('foo.bar', 'hello world!');Get values
config.get('foo'); // bar
config.get('foo.bar'); // hello worldHierarchy
The values are being overwritten. This means that the last setting we add will replace previous settings.
config
.json( { "user": "root", "pass": "secret" })
.json( { "pass": "not_so_secret" });
config.get('pass'); // not_so_secretTesting
To test you should install mocha
$ npm -g install mochaand then run
$ mocha0.1.0
10 years ago