beat-conf

0.0.2 • Public • Published

beat-conf Build Status Code Climate

Simple configuration utility for Beat dependency injection

NPM

This module provide a conf object to be injected in beat instances.

How to use

Set your configurations normally in the native package.json (abbreviated here for simplicity)

{
  ...
  "config": {
    "serverPort": "3000",
    "mongo": "mongodb://localhost:27017/production_db",
    "publicPath": "/public"
  }
}

Install this module with NPM:

npm install --save beat-conf

Declare it as a dependency of your Beat module and inject conf object where you need it

var Beat = require('beat');
var server = module.exports = new Beat('server', [
  'beat-conf',
  'http'
]);

server.run(function(http, conf){
  http.createServer().listen(conf.serverPort);
});

Config environments

This utility is very simply crafted, but it's important to understand its behavior.

The config object in package.json can contain several sub-objects whose key refers to current env.

The default one will be used, and will be overlapped by the configs according to current process.env.NODE_ENV, if exists.

As in this example:

{
  ...
  "config": {
    "default": {
      "serverPort": "3000",
      "mongo": "mongodb://localhost:27017/production_db",
      "publicPath": "/public"
    },
    "test": {
      "mongo": "mongodb://localhost:27017/test_db"
    }
  }
}

mongo property will normally be mongodb://localhost:27017/production_db;

while with process.env.NODE_ENV setted as 'test', it will be setted to mongodb://localhost:27017/test_db.

The other configurations continue the same.

githalytics.com alpha

Bitdeli Badge

Readme

Keywords

none

Package Sidebar

Install

npm i beat-conf

Weekly Downloads

2

Version

0.0.2

License

MIT

Last publish

Collaborators

  • edinella