Skip to content

Latest commit

 

History

History
75 lines (45 loc) · 1.42 KB

README.md

File metadata and controls

75 lines (45 loc) · 1.42 KB

mongorc

Read your rc config from MongoDB.

Installation

npm install mongorc

Usage

mongorc sits in front of rc and passes any config from MongoDB as a default. NOTE: this means that MongoDB config is lowest-precedence to rc.

var mongorc = require('mongorc')

mongorc(options, defaultoptions, callback)
var mongorc = require('mongorc')

var MONGODB_URL = process.env.MONGODB_URL || "localhost:27017/mydb"

mongorc({name:"myApp", configUrl:MONGODB_URL}, {foo:123}, function(err, config) {
  console.log("config:", config)
})

mongorc will also parse CLI arguments for you - similar to how rc itself will parse the --config argument.

CLI arguments:

--configUrl <mongo db url>

--configCollection <collection name> [default: "config"]

--configQuery <JSON-form mongo query>

Example of CLI arguments for an application using mongorc:

# read config from:
#   DB at localhost:27017/myapp
#   Collection name myconfig
#   Document matching query {name: "myconfig"}
node index.js \
    --configUrl localhost:27017/myapp \
    --configQuery '{"name":"myconfig"}' \
    --configCollection configuration

Because mongorc sits in front of rc, all the standard rc configuration methods will still work. So --config flag, environment variables, CLI options, etc.

Tests

Run npm test

License

BSD