1.0.0 • Published 8 years ago

mconf v1.0.0

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

mconf

=======

Build Status Coverage Status

Simple config for nodejs.

Using:

  • npm i mconf --save
  • create directory with configurations
  • create files production.js and develop.js and put them into created directory
  • create index.js file with:

    es5 and older

    var Config = require('mconf').default;
    
    if (!__dirname) {
        var __dirname = require('fs').workingDirectory;
    }
    
    var config = new Config(__dirname,['production', 'develop']);
    module.exports = config.getConfig();

    es2016+

      import Config from 'mconf';
    
      if (!__dirname) {
          var __dirname = require('fs').workingDirectory;
      }
    
      let config = new Config(__dirname,['production', 'develop']);
      module.exports = config.getConfig();
  • run your node application with export env : export NODE_ENV=production for production env.

  • By default will be used develop config.

Environment name

By default using NODE_ENV, but if you need to use another environment name:

var config = new Config(__dirname,['production', 'develop']);
module.exports = config
   .setEnv('YOUR_ENV_NAME')
   .getConfig();

Merge config strategy

By default using deep merge strategy. But if you want non deep merge ( rewrite), you should use:

var config = new Config(__dirname,['production', 'develop']);
module.exports = config
   .setDeepMerge(false)
   .getConfig();