jsconfig v0.2.0
jsconfig
loading configs from javascript files with default configs and cli support
installation
npm install jsconfigusage
jsconfig can load config file formats whatever node.js can require:
- by default it's always possible to load
*.jsfiles - if you want to use coffee-script config files, just do a require('coffee-script') before and you're able to require
*.coffeefiles as well - since node.js 0.5.x it's even possible to require
.*jsonfiles - if you're hardcore you can write your config in cpp and compile them to
*.nodefiles
var config = require('jsconfig');
config.load('./config.js', function () {
console.log(config);
});
// in another file
config = require('jsconfig'); // this is filled after config.load calla normal config file structures looks like this:
module.exports = {};config.load
config.load('./db-config.js', './server-config.js'/*, […]*/);
console.log(config);
// or
config.load('./db-config.js', './server-config.js'/*, […]*/, function () {
console.log(config);
});load all config files and fills config with all settings.
required
config.defaults
config.defaults('./db-config.default.js', './server-config.default.js'/*, […]*/);load some default config files.
config.set
config.set('ignore unknown', true); // default is falseignore all nonexisting config files and options.
does not apply on default config files.
config.set('env', {USER: 'user.name'}); // similar to config.user.name = process.env.USERdefine all environment variables, that should be included into config.
this overwrites config file values (default config files too).
config.cli
config.cli({
user: ['user.name', ['u', "user name", 'string']],
debug: [false, "debug mode", 'bool'],
}); // results only in config.user.name = opts.user (after config.load call)this sets up the command line interface. its basicly node-cli with on little change: if cli result should be saved in config, the cli-array should be packed into a second (outer) array as second element (the first is the position in the config object).
config.merge
config.merge({user:{name:'foo'}});
// or
config.merge('./hot-config.js');deep copy new values into config.