How to use the nconf.add function in nconf

To help you get started, we’ve selected a few nconf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mrvautin / adminMongo / app.js View on Github external
// if config files exist but are blank we write blank files for nconf
if(fs.existsSync(config_app, 'utf8')){
    if(fs.readFileSync(config_app, 'utf8') === ''){
        fs.writeFileSync(config_app, '{}', 'utf8');
    }
}
if(fs.existsSync(config_connections, 'utf8')){
    if(fs.readFileSync(config_connections, 'utf8') === ''){
        fs.writeFileSync(config_connections, '{}', 'utf8');
    }
}

// setup the two conf. 'app' holds application config, and connections
// holds the mongoDB connections
nconf.add('connections', {type: 'file', file: config_connections});
nconf.add('app', {type: 'file', file: config_app});

// set app defaults
var app_host = process.env.HOST || '0.0.0.0';
var app_port = process.env.PORT || 1234;

// get the app configs and override if present
if(nconf.stores.app.get('app:host') !== undefined){
    app_host = nconf.stores.app.get('app:host');
}
if(nconf.stores.app.get('app:port') !== undefined){
    app_port = nconf.stores.app.get('app:port');
}
if(nconf.stores.app.get('app:locale') !== undefined){
    i18n.setLocale(nconf.stores.app.get('app:locale'));
}
github learnlinux / tuxlab-app / server / imports / startup / settings.js View on Github external
nconf = require('nconf');

// Import from process.env and process.argv
  nconf.argv().env();

// Import from /private assets
  nconf.add('env', { type: 'literal', store: JSON.parse(Assets.getText("settings.env.json"))});
  nconf.add('domain', { type: 'literal', store: JSON.parse(Assets.getText("settings.domain.json"))});
  nconf.add('labvm', { type: 'literal', store: JSON.parse(Assets.getText("settings.labvm.json"))});
  nconf.add('google', { type: 'literal', store: JSON.parse(Assets.getText("settings.google.json"))});
// Set Defaults
github hatamiarash7 / MongoDB_Admin / app.js View on Github external
// if config files exist but are blank we write blank files for nconf
if(fs.existsSync(config_app, 'utf8')){
    if(fs.readFileSync(config_app, 'utf8') === ''){
        fs.writeFileSync(config_app, '{}', 'utf8');
    }
}
if(fs.existsSync(config_connections, 'utf8')){
    if(fs.readFileSync(config_connections, 'utf8') === ''){
        fs.writeFileSync(config_connections, '{}', 'utf8');
    }
}

// setup the two conf. 'app' holds application config, and connections
// holds the mongoDB connections
nconf.add('connections', {type: 'file', file: config_connections});
nconf.add('app', {type: 'file', file: config_app});

// set app defaults
var app_host = process.env.HOST || 'localhost';
var app_port = process.env.PORT || 1234;

// get the app configs and override if present
if(nconf.stores.app.get('app:host') !== undefined){
    app_host = nconf.stores.app.get('app:host');
}
if(nconf.stores.app.get('app:port') !== undefined){
    app_port = nconf.stores.app.get('app:port');
}
if(nconf.stores.app.get('app:locale') !== undefined){
    i18n.setLocale(nconf.stores.app.get('app:locale'));
}
github mrvautin / adminMongo / app.js View on Github external
// if config files exist but are blank we write blank files for nconf
if(fs.existsSync(config_app, 'utf8')){
    if(fs.readFileSync(config_app, 'utf8') === ''){
        fs.writeFileSync(config_app, '{}', 'utf8');
    }
}
if(fs.existsSync(config_connections, 'utf8')){
    if(fs.readFileSync(config_connections, 'utf8') === ''){
        fs.writeFileSync(config_connections, '{}', 'utf8');
    }
}

// setup the two conf. 'app' holds application config, and connections
// holds the mongoDB connections
nconf.add('connections', {type: 'file', file: config_connections});
nconf.add('app', {type: 'file', file: config_app});

// set app defaults
var app_host = process.env.HOST || '0.0.0.0';
var app_port = process.env.PORT || 1234;

// get the app configs and override if present
if(nconf.stores.app.get('app:host') !== undefined){
    app_host = nconf.stores.app.get('app:host');
}
if(nconf.stores.app.get('app:port') !== undefined){
    app_port = nconf.stores.app.get('app:port');
}
if(nconf.stores.app.get('app:locale') !== undefined){
    i18n.setLocale(nconf.stores.app.get('app:locale'));
}
github blacktail / real-edit / lib / config_util.js View on Github external
var nconf = require('nconf');

var commentedJson = {
    stringify: function (obj, replacer, spacing) {
        return JSON.stringify(obj, replacer || null, spacing || 2);
    },
    parse: function (obj) {
        return JSON.parse(removeComments(obj));
    }
};

nconf.add('main', {
    type: 'file',
    format: commentedJson,
    file: 'config/config.json'
});

module.exports = nconf.get();

/**
 * Thank you for this work by James padolsey who provide 'removeComments' function on the following web site.
 *
 * http://james.padolsey.com/javascript/javascript-comment-removal-revisted/
 */

function removeComments(str) {

    var uid = '_' + +new Date(),
github bem-archive / bem-site-engine / src / blocks / server.blocks / config / config.node.js View on Github external
].forEach(function (item) {
        nconf.add(item,   {
            type: 'file',
            file: path.resolve(process.cwd(), 'configs', (item + '.json'))
        });
    });
github bem-archive / bem-site-engine / src / config.js View on Github external
].forEach(function(item) {
    nconf.add(item,   {
        type: 'file',
        file: path.resolve(process.cwd(), 'configs', (item + '.json'))
    });
});
github bem-archive / bem-site-engine / src / data / config.js View on Github external
['current/app', 'common/app'].forEach(function (item) {
    nconf.add(item,   {
        type: 'file',
        file: path.resolve(process.cwd(), 'configs', (item + '.json'))
    });
});

nconf

Hierarchical node.js configuration with files, environment variables, command-line arguments, and atomic object merging.

MIT
Latest version published 6 months ago

Package Health Score

82 / 100
Full package analysis