0.0.6 • Published 10 years ago

icnf v0.0.6

Weekly downloads
2
License
BSD
Repository
github
Last release
10 years ago

ICNF

icnf is a nodejs module for supporting simple configeration in json format (but powerfull).

License: GPL/BSD

Intro

There already exists a module named config, but for me, it is too large -- i dont want supporting yml etc features, i just want a simple solution but exactly have what i want.

So that's why i do this module. And of cause choice is yours.

How to install

npm install icnf

How to use

  1. create several config files under etc/ directory in your project, for example:

    <YOUR PROJECT>
    + etc/
      + production.json
      + testing.json
      + development.json
    		comm/   -- this contains comm settings for all of the environments, but still configerable
    			+ comm.json
    			+ comm2.json
  2. use icnf in your code

    var icnf = require('icnf')(__dirname);
    // app root directory, that is <YOUR PROJECT>
    
    var config = icnf(); 
    // default is process.env.NODE_ENV || 'production', so it will automatically choose etc/production.json.
    
    var config = icnf('development'); 
    // choose etc/development.json explicitly

How to use idiff

There is also a tool named idiff under bin/ above v0.0.3. This tool only check the key in the config file. For example:

$ idiff production
  checking /Users/yarco/Sites/js/icnf/test/etc/development.json
- database.port
- database.more.name
! database.more.port
- keywords.1

Argument production is the standard config file in this example. (That means you may treat that file as a standard.) This file should be located in etc/ (etc/production.json).

  • - means the key database.port is lost in development.json when comparing to production.json
  • ! means type does't match

Notice:

  • Array like keys (ex. keywords here) will always treat as an object.
  • Key exists in development but not in production will be totally ignored.
  • extend part won't be checked. cause it is used for common part

Here is development to production (you could also add more files there, ex. testing.json):

$ idiff development
  checking /Users/yarco/Sites/js/icnf/test/etc/production.json
- gf
- database.more.kk
! database.more.port

Extra notice

  • config file is <PROJECT>/etc/<ENV>.json, the name of etc is fixed
  • the directory for comm part is comm (<PROJECT>/etc/comm/<YOUR>.json), is also fixed
  • files in subdirectories under etc/ will be totally ignored when using idiff
  • You can use environment variable now (>= v0.0.5), just prefix with $, for example: { "NODE_ENV": "$NODE_ENV" }. $NODE_ENV will be expanded to its real value.

ChangeLog

  • 0.0.5 to 0.0.6
    • add supporting multi-confs in extend keyword, see example: test/etc/production.json , key extend * add key extendEnvValue in config if you want to disable checking environment variable
  • 0.0.4 to 0.0.5 * add support for environment variables, the value prefix with '$' will be expanded. (that means "KEY": "$VALUE" will be treated as "KEY": process.env.VALUE )
  • 0.0.3 to 0.0.4
    • move repos from yarcowang/icnf to Yet-Another-Org/node-icnf
    • change a bit README
    • add default argument in idiff (so, it will default choose process.env.NODE_ENV || 'production' without type production
  • 0.0.1 to 0.0.3
    • add idiff
    • add extend feature for common part, see example under tests/

Contact

You could contact me through yarco.wang@gmail.com according to further debugging or maintance. Programming related topics are also welcomed.

timezone: GMT+0800

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

12 years ago

0.0.1

12 years ago