set

setconfig

A Configuration Loader for Node.js

Showing:

Popularity

Downloads/wk

22

GitHub Stars

0

Maintenance

Last Commit

6yrs ago

Contributors

0

Package

Dependencies

1

Size (min+gzip)

10.6KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

NPM   Build Status

setConfig

A Configuration Loader for Node.js

(C) Pradeep Mishra pradeep23oct@gmail.com

Load configuration for node.js application on enviroment basis.

setConfig follows some convention to simplify config loading and handling.

Features

  • Simple to use
  • Supports commenting in configuration json file
  • Helper functions to handle configuration

Example usage

setConfig use default.json for loading default configuration and {enviroment}.json for loading environment specifc configuration.

/myApp/configs/default.json

{
  // default  config
  "db": {
      "host": "localhost",
      "port": 1234,
      "name": "users"
    },
    "rateLimit": {
      "limit": 100
      // comment is also supported in config json files
    },
    "flag" : false
}

/myApp/configs/development.json

{
  // dev  config
    "rateLimit": {
      "limit": 1000
      // comment is also supported in config json files
    }
}

var setConfig = require('setconfig');

// instantiate setConfig
var config = new setConfig();

/*
SetConfig support environment variable to set application's enviroment 
and configuration directory path.

NODE_ENV=development
NODE_CONFIG_DIR=/myApp/configs/

OR
You can set it programatically

*/
var configDir = __dirname + '/config';
config.setpath(configDir);
config.setEnv('development');

// call load method to load all configurations

config.load();

// now setConfig is ready to use

// get property
config.get('rateLimit');

// get internal config properties with period
config.get('rateLimit.limit');

// set property
config.set('flag', true);

// remove property
config.remove('rateLimit');

// check property exist
config.has('rateLimit.limit');

// get current environment
config.getEnv();

// returns JSON representation of current configuration
config.toJSON();
npm install setconfig --save

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100