Skip to content

Instantly share code, notes, and snippets.

@carlos8f
Forked from cpsubrian/README.md
Created May 2, 2012 20:05
Show Gist options
  • Save carlos8f/2579894 to your computer and use it in GitHub Desktop.
Save carlos8f/2579894 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.pubsub.module=amino-custom

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

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

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