Code Monkey home page Code Monkey logo

node-setconfig's Introduction

NPM   Build Status

setConfig

A Configuration Loader for Node.js

(C) Pradeep Mishra [email protected]

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

node-setconfig's People

Contributors

pradeep-mishra avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.