Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Tagged configuration
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
.travis.yml
README.md
index.js
package.json
test.js

README.md

c-c-config is a library to parse tagged configuration. Build Status

As an example, take the following JSON config which describes different database servers to use for different application environments:

{
    "development": {
        "database": "localhost"
    },
    "production": {
        "database": "power-hungry-server"
    }
}

You'd use this with c-c-config as follows:

var ccconfig = require("c-c-config");

// c-c-config does not concern itself with I/O.
var raw = JSON.parse(/* … */);

var cfg = ccconfig("development", raw);
// do something with cfg.database

However, multiple tags (and thus levels of configuration) are possible:

ccconfig("worker development", {
    "worker development": {
        "bindPort": 91234
    },
    "worker": {
        "bindPort": 1234
    },
    "development": {
        "database": "localhost"
    }
});

The most specific rule will prevail, so bindPort will be set to 91234. Objects are merged, so the resulting object will also contain the database property. (In fact, c-c-config does deep merging of object structures.)

There's also the ability to pass in defaults:

var defaults = {
    "bindHost": "0.0.0.0",
    "bindPort": 3000
};
ccconfig("worker", defaults, {
    "worker": {
        "bindPort": 91234
    }
});
Something went wrong with that request. Please try again.