adon-config
This module is used for managing system configurations in cascading order.
Last updated 3 years ago by adonisv79 .
GPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install adon-config 
SYNC missed versions from official npm registry.

adon-config

This module is used for managing system configurations in cascading order. It is able to load recursively load all the files in the folder and form the exact structure in the config object.

assuming you have a javascript config file with the following item in config/common

modules.export = {
  test: {
    something: 'eureka!'
  }
}

you can retrieve them easily by

let config = require('adon-config').load(); //this should be one of the first line of code in your index file

config.load(__dirname);
console.log("My test value is " + config.get('test.something'));

Goal of this module

  • Allows developers to manage configuration files in a common structure
  • Support a mix of common config file types (Javascript, JSON)
  • Allows overriding of configurations data on different module levels
  • Allows special configurations based on server environment (NODE_ENV)

Installation

$ npm install adon-config --save

Setup

  1. In your node project, create a "config/common" folder where you want all the config files to exist.
  2. (optional) create an "config/env" folder within as well to contain environment specific configurations.
  3. inside these config folder create any files (javascript or json)
root
  |-config
  |     |-common 
  |     |   |-server.js
  |     |   |-database.js
  |     |-env 
  |     |   |-development
  |     |   |   |-server.js
  |     |   |   |-test.js
  |     |   |-production
  |     |   |   |-server.js
  |-index.js

in the sample above, we have 2 configurations that will be common across all environments. The config object will contain the attributes or elements named 'server' and 'database' based on the config files.

let config = require('adon-config').get()
console.log(config.database.source); //outputs the source value from common/database

The env (environment) overrides common configurations and will rely on the systm's NODE_ENV value. in the sample above, any duplicate values in config.server (based from common/server.js) will be overridden by the environment version. any unique configuration that exists in an environment only exists for that environment (i.e. development/test.js)

Functions

###Load loads the config folder from the current project directory then returns the latest config object (this is the first code you must trigger to initialize this module)

let config = require('adon-config').load()

just returns the latest config object and do nothing else (used for succeeding requests where loading of configurations are no longer needed)

let config = require('adon-config').get()

Dependencies

adon-config relies on the following node modules

Source codes

adon-config is publicly available on Github

License

GPL

Current Tags

  • 2.0.0                                ...           latest (3 years ago)

12 Versions

  • 2.0.0                                ...           3 years ago
  • 1.2.3                                ...           3 years ago
  • 1.2.2                                ...           3 years ago
  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.5                                ...           4 years ago
  • 1.0.4                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 7
Last Day 0
Last Week 0
Last Month 2
Dependencies (1)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2016 © taobao.org |