1.0.4 • Published 8 years ago

configamajig v1.0.4

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

Configamajig

Load configuration files with environment and local overrides!

The priorities from low to high are default.json -> <environment>.json -> local.json. You will generally want to have local.json in your .gitignore as this will be the place for devs to override the config options they want.

Usage

In this example we have a project structure like this:

|-- config
|   |-- default.json
|   |-- local.json
|   `-- production.json
`-- script.js

Specify your defaults in default.json. They will be the the final values if nothing overrides them.

default.json

{
    "port": 8080
}

You can specify environment config files. They correspond to whatever is set in the NODE_ENV environment variable. For example if NODE_ENV === 'production' this file would be loaded and override the port in default.json.

production.json

{
    "port": 80
}

Here is where we can override all default and environment config options. If we are a 1337 haxor we can make the port 1337 on our machine.

local.json

{
    "port": 1337
}

Here we require Configamajig and use the default config directory of ./config. If you wish to specify a different directory you can just pass it as a parameter.

script.js

var config = require('configamajig')();
// Same as
// var config = require('configamajig')('./config');

// Simple echo url server using port from config.
require('http').createServer(function (req, res) {
    console.log(req.url);
    res.write(req.url);
    res.end();
}).listen(config.port);

Play around with the configs in examples/ and run node example.js to see the effects.

Installation

$ npm install configamajig

Test

$ npm test

Changelog

DateVersionDescription
2016-02-23v1.0.2Switched to using deep copy. Duh.
2016-02-20v1.0.1Wasn't using process.cwd() for path resolution
2016-02-19v1.0.0Initial release! :)
1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago