Skip to content

Instantly share code, notes, and snippets.

@cpsubrian
Created May 2, 2012 19:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cpsubrian/2579715 to your computer and use it in GitHub Desktop.
Save cpsubrian/2579715 to your computer and use it in GitHub Desktop.
Tiered config example with nconf

Startup a service that depends on amino

./bin/myservice --conf=/path/to/my/conf

Startup a service using the default conf path

./bin/myservice

Startup a service using a conf file and overriding one driver

./bin/myservice --conf=/path/to/conf --amino.driver.pubsub.module=amino-pubsub-custom

Startup cantina conf service using just one conf file for both amino and cantina

./bin/cantina-conf --amino.conf=/etc/cantina.conf.json

{
"amino": {
"drivers": {
"pubsub": {
"module": "amino-pubsub-redis",
"options": {
"host": "localhost",
"port": 1337
}
},
"queue": {
"module": "amino-queue-amqp",
"options": {
"host": "localhost",
"port": 12345
}
},
"request": {
"module": "amino-request-http"
}
}
}
}
var nconf = require('nconf'),
fs = require('fs');
// Favor command-line arguments and environment variables.
nconf.env().argv();
// Check for a config file or the default location.
if (path = nconf.get('conf')) {
nconf.file({file: path});
}
else if (fs.statSync('/etc/amino.conf.json')) {
nconf.file({file: '/etc/amino.conf.json'});
}
// Defaults.
nconf.defaults({
amino: {
drivers: {
pubsub: {
module: 'amino-pubsub-redis',
options: {
host: 'localhost',
port: 1337
}
},
queue: {
module: 'amino-queue-amqp',
options: {
host: 'localhost',
port: 12345
}
},
request: {
module: 'amino-request-http'
}
}
}
});
// Start working with the config here.
{
"cantina": {
"conf" {
"store": "redis",
"options": {
"host": "localhost",
"port": 1337,
"namespace": "cantina:conf"
}
},
},
"amino": {
"drivers": {
"pubsub": {
"module": "amino-pubsub-redis",
"options": {
"host": "localhost",
"port": 1337
}
},
"queue": {
"module": "amino-queue-amqp",
"options": {
"host": "localhost",
"port": 12345
}
},
"request": {
"module": "amino-request-http"
}
}
}
}
{
"connector": {
"site" {
"title": "AwesomeConnector"
}
},
"cantina": {
"conf" {
"store": "redis",
"options": {
"host": "localhost",
"port": 1337,
"namespace": "cantina:conf"
}
},
},
"amino": {
"drivers": {
"pubsub": {
"module": "amino-pubsub-redis",
"options": {
"host": "localhost",
"port": 1337
}
},
"queue": {
"module": "amino-queue-amqp",
"options": {
"host": "localhost",
"port": 12345
}
},
"request": {
"module": "amino-request-http"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment