npm

Need private packages and team management tools?Check out npm Orgs. »

con-fig

1.0.5 • Public • Published

con-fig

Simplified Configuration

  • Load a configuration JSON object
  • Get/Set values by keyname, namespace
  • Get and Set values on a per environment basis (NODE_ENV: development vs production)

installation

npm install con-fig --save

usage

var Config = require('con-fig');
var config = new Config( require('./your-config.json') );

You can structure you json configuration by NODE_ENV and/or by namespace and NODE_ENV.

var config = new Config({
  "state": "Oregon",
  "development": {
    "state": "Washington"
  },
  "test": {
    "state": "California"
  },
  "production": {
    "state": "Nevada"
  },
  "east": {
    "state": "Rhode Island",
    "development": {
      "state": "North Carolina"
    },
    "test": {
      "state": "South Carolina"
    },
    "production": {
      "state": "Maine"
    }
  }
});

In the above configuration (without specifying a namespace):

config.get('state');

// returns "California" if the NODE_ENV is set to "test"
// returns "Washington" if the NODE_ENV is set to "development"
// returns "Nevada" if the NODE_ENV is set to "production"
// returns "Oregon" if the NODE_ENV is not set"

In the above configuration (specifying a namespace):

config.get('state', 'east');

// returns "South Carolina" if the NODE_ENV is set to "test"
// returns "North Carolina" if the NODE_ENV is set to "development"
// returns "Maine" if the NODE_ENV is set to "production"
// returns "Rhode Island" if the NODE_ENV is not set"

You can also get back a default value if you want.

config.get('bacon', 'east', 'nope');

// returns nope

Or set an existing value

config.set('state', 'bacon');

// returns true
config.set('bacon', 'bacon');

// returns false - bacon doesn't exist

Or merge in new values

config.merge({ 'bacon': 'bacon' });

docs

There are docs that you can generate and read.

grunt docs

tests

There's a lot of tests. You should probably look at them. Or run them:

grunt test

install

npm i con-fig

Downloadsweekly downloads

14

version

1.0.5

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability