$ npm install kea-config --save
let config.web = {
port: 3005,
paging: {
itemsPerPage: 25,
visiblePages: 10
}
}
export default config;
let config.web = {
port: 4343
};
export default config;
let config.web = {
port: 80
};
export default config;
import configManager from 'kea-config';
configManager.setup('./config');
// For process.env.NODE_ENV === 'development';
configManager.get('web.port'); // 4343
// For process.env.NODE_ENV === 'production';
configManager.get('web.port'); // 80
import configManager from 'kea-config';
configManager.init('./config/main');
configManager.get('web.port'); // 3005
let config.web = {
port: 3005,
paging: {
itemsPerPage: 25,
visiblePages: 10
}
}
export default config;
configManager.get('web.port'); // 3005
configManager.get('web.paging');
/*
{
itemsPerPage: 25,
visiblePages: 10
}
*/
{
nameValue: 'loginName',
sessionKey: '6ketaq3cgo315rk9',
dbParams: {
username: { $ref: 'web.nameValue' },
password: '12345'
},
dbConnection: {
user: { $ref: 'web.dbParams' },
key: { $ref: 'web.sessionKey' }
},
dbConectionStr: {
$ref: 'web.dbConnection',
$tmpl: 'db:{user.username}::{user.password}@{key}'
}
}
configManager.get('dbConnection');
//should return object
// {
// user: {
// username: 'loginName',
// password: '12345'
// },
// key: '6ketaq3cgo315rk9'
// }
configManager.get('dbConectionStr');
// should return string
// 'db:loginName::12345@6ketaq3cgo315rk9'
configManager.get('some.long.key')
// return key value
configManager.set('other.key', true)
// return `this` reference for chaining
configManager.has('other.key') // true
var Hapi = require('hapi');
var server = new Hapi.Server();
var pluginOptions = {
confPath: './path-to-config-flies',
decorateServer: true
};
// for hapi >= 8.0.0 or use server.pack.register for hapi < 8.0.0
server.register({
plugin: require('hapi-kea-config'),
options: pluginOptions
}, function(err) {
if (err) {
console.log('error', 'Failed loading plugin: hapi-kea-config');
}
});
// Usage in the code
var configManager = server.plugins['hapi-kea-config'];
if (configManager.has('web')) {
var port = configManager.get('web.port');
}
Inspired by web.config transformations in ASP.NET
100% code coverage by tests
High performance (a few millions operations per sec simple get / set operations and a few tens of thousands operations per sec for key with references and templates)
Gulp used for test, benchmarks and preparing README.md