UNPKG

1.25 kBJavaScriptView Raw
1var fs = require('fs'),
2 path = require('path'),
3 nconf = require('./lib/nconf');
4
5//
6// Configure the provider with a single store and
7// support for command-line arguments and environment
8// variables.
9//
10var single = new nconf.Provider({
11 env: true,
12 argv: true,
13 store: {
14 type: 'file',
15 file: path.join(__dirname, 'config.json')
16 }
17});
18
19//
20// Configure the provider with multiple hierarchical stores
21// representing `user` and `global` configuration values.
22//
23var multiple = new nconf.Provider({
24 stores: [
25 { name: 'user', type: 'file', file: path.join(__dirname, 'user-config.json') },
26 { name: 'global', type: 'global', file: path.join(__dirname, 'global-config.json') }
27 ]
28});
29
30//
31// Setup nconf to use the 'file' store and set a couple of values;
32//
33nconf.use('file', { file: path.join(__dirname, 'config.json') });
34nconf.set('database:host', '127.0.0.1');
35nconf.set('database:port', 5984);
36
37//
38// Get the entire database object from nconf
39//
40var database = nconf.get('database');
41console.dir(database);
42
43//
44// Save the configuration object to disk
45//
46nconf.save(function (err) {
47 fs.readFile(path.join(__dirname, 'config.json'), function (err, data) {
48 console.dir(JSON.parse(data.toString()))
49 });
50});
\No newline at end of file