0.2.0 • Published 12 years ago

jsconfig v0.2.0

Weekly downloads
66
License
-
Repository
github
Last release
12 years ago

jsconfig

loading configs from javascript files with default configs and cli support

installation

npm install jsconfig

usage

jsconfig can load config file formats whatever node.js can require:

  • by default it's always possible to load *.js files
  • if you want to use coffee-script config files, just do a require('coffee-script') before and you're able to require *.coffee files as well
  • since node.js 0.5.x it's even possible to require .*json files
  • if you're hardcore you can write your config in cpp and compile them to *.node files
var config = require('jsconfig');
config.load('./config.js', function () {
    console.log(config);
});

// in another file
config = require('jsconfig'); // this is filled after config.load call

a 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 false

ignore 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.USER

define 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.

0.2.0

12 years ago

0.1.3

12 years ago

0.1.2

12 years ago

0.1.1

12 years ago

0.1.0

13 years ago

0.0.1

13 years ago