exports.register = () => { const rootPath = path.join(__dirname, '../'); const configFile = 'config.json'; // 1. any overrides nconf.overrides({}); // 2. process.env // 3. process.argv nconf.env() .argv(); // 4. Values in config.json nconf.file(rootPath + configFile); // 5. Any default values nconf.defaults({ application: { port: 3100 } }); // Log current configuration winston.info('app - config: logging: ', nconf.get('logging')); winston.info('app - config: config file loaded from: ', rootPath + configFile); winston.info('app - config: application:', nconf.get('application')); winston.info('app - config: nconf loaded'); };
module.exports = (function() { 'use strict'; var nconf = require('nconf'); nconf.overrides({'a': 1}); console.log("NCONF INDEX.JS ['a'] is "+nconf.get('a')); var testy = require('./testcode'); }());
getConfig(nconf.get("NODE_ENV")).then(function(config){ nconf.overrides(config); if(nconf.get('MAMBO_BACKEND') === 'magneto'){ if(!magneto.server){ magneto.server = magneto.listen(nconf.get('MAGNETO_PORT'), next); return; } } return next(); });
/** * Resets and initializes the system-wide configuration using {@link * https://github.com/flatiron/nconf|nconf}. * * @param {boolean} isMaster flag indicating whether this process is * the cluster master * @param {object} [baseConfig] base configuration object (just for * testing, read from file by default) * @param {object} [localConfig] local configuration object (just for * testing, read from file by default) * @throws {ConfigError} if no valid configuration for the local host * could be found */ function init(isMaster, baseConfig, localConfig) { reset(); baseConfig = baseConfig || require(CFG_BASE); localConfig = localConfig || require(CFG_LOCAL); // environment variables take precedence: nconf.env(); // ...then cmdline arguments: nconf.argv(); // ...then anything in local config file: nconf.overrides(localConfig); // ...default values for anything not specified otherwise: nconf.defaults(baseConfig); initClusterConfig(isMaster); if (gsid === null) { throw new ConfigError('invalid network configuration for this host ' + '(unable to initialize GSID)'); } }
module.exports = function (options) { nconf.overrides(options); nconf.env(['debug', 'NODE_ENV']); process.env.NODE_ENV = nconf.get('NODE_ENV') || 'production'; nconf.file('secrets', { type: 'file', file: path.join(__dirname, 'secrets', process.env.NODE_ENV + '.json') }); nconf.file('default', { type: 'file', file: path.join(__dirname, 'defaults.json') }); return nconf; };
module.exports = function (testBeansFilename) { var nconf = require('nconf'); var merge = require('utils-merge'); var Beans = require('CoolBeans'); require('./shutupWinston')(); // beans: var productionBeans = require('../config/beans.json'); var testBeans = require('../config/' + testBeansFilename); merge(productionBeans, testBeans); nconf.overrides({ port: '17125', swkTrustedAppName: null, swkTrustedAppPwd: null, swkRemoteAppUser: null, dontUsePersistentSessions: true, superuser: '******', wikipath: '.', beans: new Beans(productionBeans), transport: null, 'transport-options': null, 'sender-address': null, publicUrlPrefix: 'http://localhost:17125', secret: 'secret', githubClientID : null, githubClientSecret : null, publicPaymentKey: null, secretPaymentKey: null, paymentBic : 'paymentBic', paymentIban : 'paymentIban', paymentReceiver : 'paymentReceiver', domainname : 'localhost' }); return require('../configure'); };
module.exports = function (env) { 'use strict'; // Configuration object. var config = {}; config.path = __dirname + '/config'; config.baseFile = config.path + '/base.json'; config.overrideFile = config.path + '/config.json'; // overrides should be the very first thing if (fs.existsSync(config.overrideFile)) { nconf.overrides(JSON.parse(fs.readFileSync(config.overrideFile))); console.log('Loading overrides from ' + config.overrideFile); } // THEN use env & args nconf.env().argv(); var NODE_ENV = nconf.get('NODE_ENV') || 'development'; if (env && (NODE_ENV !== env)) { nconf.set('NODE_ENV', env); NODE_ENV = env; } config.environmentFile = config.path + '/' + NODE_ENV + '.json'; // finally the config file and defaults nconf.file({ file: config.environmentFile }); nconf.defaults(JSON.parse(fs.readFileSync(config.baseFile, 'utf-8'))); nconf.set('applicationPath', __dirname + '/'); return config; };
, pkg = require(__dirname + "/../package.json") , env = process.env.NODE_ENV; /** * when running tests in OSX, we actually want to use dev settings */ if(!env || (env==='test' && process.platform==='darwin')) { env = 'development'; } var IS_DEV = (env==='development'); module.exports = nconf .overrides({ store: { "pkg": _.omit(pkg, 'main', 'scripts', 'dependencies', 'devDependencies') } }) .argv() // .env({separator:'__'}) .file('config', { file: __dirname + '/config.ini' , format: nconf.formats.ini }) .file('config-env', { file: __dirname + '/config-' + env + '.ini'
configLocalJs.forEach(function (f) { console.log('found valid config file',f) nconf.overrides(require(configDir + '/' + f)); });
else { console.log('Invalid environment (use either "--dev" or "--production"'); process.exit(); } // manually update the 'env' configuration property (to be used throughout the application); this is // equivalent to the traditional NODE_ENV Nconf.set('env', env); // the NODE_ENV env variable is used by webpack to build different targets, so we set it as well; // note that by setting "export NODE_ENV=..." in the shell won't have any effect because we are // setting the property directly in the process.env object process.env.NODE_ENV = env; global.NODE_ENV = env; Nconf.overrides(require(configPath)); // 4 - load the default configuration (these options will be applied only if they aren't already) const defaultPath = './default.js'; Nconf.defaults(require(defaultPath)); // 5 - output info console.log(Chalk.green('=================')); console.log(Chalk.bold('Configuration has been loaded')); console.log('1. default configuration file: ', Chalk.bold(Path.join(__dirname, defaultPath))); console.log('2. environment configuration (overrides default config): ', Chalk.bold(Path.join(__dirname, configPath))); let argv = ''; for (let i = 2; i < process.argv.length; ++i) { argv += process.argv[i] + ' '; }
var nconf = require('nconf'); nconf.overrides({ "SERVICE_CONFIGS": "master:accounts:/apis/v/configs", "SERVICE_TOKENS": "master:accounts:/apis/v/tokens", "SERVICE_OTPS": "master:accounts:/apis/v/otps", "LOCAL_USERS": __dirname + "/..:accounts:/apis/v/users" }); require('pot');
var request = require('request'); var _ = require('lodash'); var mysql = require('mysql'); var fs = require('fs'); var events = require('events'); var nconf = require('nconf'); /*---------------------------------------------------------------------------*/ // Config // if testing then want to make sure we are using testing db if (process.env.NODE_ENV == 'test') { nconf.overrides({'WNU_DB_URL': process.env.WNU_TEST_DB_URL}); } // config files take precedence over command-line arguments and environment variables nconf.file({ file: 'config/' + process.env.NODE_ENV + '.json' }) .argv() .env(); // provide sensible defaults in case the above don't nconf.defaults({ timeout: 20000,
if ( overrideMap.hasOwnProperty( overrideField ) ) { if ( process.env[overrideField + "_HOST"] ) { var value = "http://" + process.env[overrideField + "_HOST"]; if ( process.env[overrideField + "_PORT"] ) { value += ":" + process.env[overrideField + "_PORT"]; } if ( value ) { for ( var i = 0; i < overrideMap[overrideField].length; i++ ) { confOverrides[overrideMap[overrideField][i]] = value; } } } } } nconf.overrides( confOverrides ).env(); try { nconf.defaults( JSON.parse( fs.readFileSync( envConfigFile, 'utf-8' ) ) ) } catch ( ex ) { logger.log( 'warning', 'environment config file not found: ' + envConfigFile ); } nconf.file( {file: __dirname + '/config.json'} ); if ( !nconf.get( "GOOGLE_OAUTH1_CLIENT_KEY" ) ) { throw("FATAL: GOOGLE_OAUTH1_CLIENT_KEY not defined"); } if ( !nconf.get( "GOOGLE_OAUTH1_CLIENT_SECRET" ) ) { throw("FATAL: GOOGLE_OAUTH1_CLIENT_SECRET not defined");
'use strict'; var nconf = require('nconf'); nconf.argv(); nconf.env('_'); var environment = process.env.NODE_ENV || 'development'; var env = require('./' + environment); nconf.overrides(env); module.exports = { get: function (key) { return nconf.get(key); } };
var nconf = require('nconf'); var fs = require('fs'); var baseConfig = JSON.parse(fs.readFileSync('./config/config.json', 'utf8')); nconf.overrides(baseConfig); nconf.argv() .env() .file({ file: './config/' + process.env.ENVIRONMENT + '/config.json' }); nconf.defaults(baseConfig); nconf.use('memory'); module.exports = nconf;
'use strict'; var nconf = require('nconf') , path = require('path') , env = process.env.NODE_ENV || 'development' , root = process.cwd(); nconf.overrides({ env : env , github : require('./github.json') , path : { root : root , config : path.join(root, 'config', env) + '.json' } }); nconf.env(); nconf.argv(); nconf.file(env, nconf.get('path:config')); nconf.defaults(require('./default.json')); module.exports = nconf;
// run tests locally or with test collection var nconf = require('nconf'); nconf.overrides({ mongoUrl : 'mongodb://192.168.59.103/ayp-test' }); nconf.file({file: 'config.json', dir:'../../', search: true}); var chai = require('chai') , expect = chai.expect , express = require('express') , request = require('supertest') , models = require('ayp-models').init(nconf) , User = models.user , Photo = models.photo , passport = require('ayp-models').passport , sessionOptions = { passport: passport, secret: nconf.get('sessionSecret') } , api = require('../index.js') , fixtures = require('./fixtures/db') , app , token , cookie; console.debug = function(){}; describe('library', function() { before(function (done) { var web = express(); web.use(express.urlencoded()); web.use(express.json());
var nconf = require('nconf'); nconf.overrides({ "SERVICE_CONFIGS": "master:accounts:/apis/v/configs", "SERVICE_BINARIES": "master:accounts:/apis/v/binaries", "SERVICE_CLIENTS": "master:accounts:/apis/v/clients", "SERVICE_USERS": "master:accounts:/apis/v/users", "SERVICE_TOKENS": "master:accounts:/apis/v/tokens", "LOCAL_VEHICLES": __dirname + "/..:autos:/apis/v/vehicles" }); require('pot');
'use strict'; var nconf = require('nconf'); nconf.overrides({ superuser: ['Bobby'] }); module.exports = require('../configure');
, Fs = require('fs') , Path = require('path') ; if (!nconf._loaded) { nconf._loaded = 'by alice'; var Pluto = require('pluto') ; nconf.overrides( { 'alice' : { 'dir' : process.cwd() , 'releases_dir' : Path.join(process.cwd(), 'releases') , 'prefix' : Fs.realpathSync(__dirname + '/..') , 'node_version' : process.version } , 'pluto' : Pluto.config.overrides }); // // 2. `process.env` // 3. `process.argv` // nconf.env(); nconf.argv(); // // 4. Values in `config.json`
// beans: var productionBeans = require('../config/beans.json'); var testBeans = require('../config/testbeans.json'); merge(productionBeans, testBeans); nconf.overrides({ port: '17125', swkTrustedAppName: null, swkTrustedAppPwd: null, swkRemoteAppUser: null, dontUsePersistentSessions: true, superuser: '******', wikipath: '.', beans: new Beans(productionBeans), transport: null, 'transport-options': null, 'sender-address': null, publicUrlPrefix: 'http://localhost:17125', secret: 'secret', githubClientID: null, githubClientSecret: null, publicPaymentKey: null, secretPaymentKey: null, paymentBic: 'paymentBic', paymentIban: 'paymentIban', paymentReceiver: 'paymentReceiver' }); module.exports = require('../configure');
'use strict'; var nconf = require('nconf'); nconf.overrides({ superuser: ['Charli'] }); module.exports = require('../configure');
//dependencies var configJson = require('../config.json'); var packageJson = require('../package.json'); var test = require('unit.js'); var should = test.should; var httpMocks = require('node-mocks-http'); var nconf = require('nconf'); //set some defaults! var TEST_PORT = '7777'; var TEST_MESSAGE = 'Welcome'; var TEST_PERSON = 'Alice'; // Setup nconf to use in-order: you have to flag them last-in-first-out. // 1. Overrides - blows away any other values for the same keys nconf.overrides({ 'SERVER_PORT_FROM_ENV': TEST_PORT, 'MESSAGE_FROM_ENV': TEST_MESSAGE, 'PERSON_FROM_ARG': TEST_PERSON }); // the unit under test var sampleService = require('../sample-server'); //star test descriptions describe('SampleServer-UnitTests', function() { before(function(done) { done(); }); after(function(done) { done(); });
var nconf = require('nconf') nconf.argv().env() nconf.overrides({ tokens: { secret: 'TestSecretKey', expires: 900 } }) var is = require('../../src/webserver') describe('installServer.js', function () { it('should start install server', function (done) { if (is.server.listening) is.server.close() is.installServer(function () { done() }) }) })
* Load configuration */ nconf .argv() .env(); var development = true; if (process.env.NODE_ENV && process.env.NODE_ENV == "production") { development = false; } nconf.overrides({ development: development }); nconf.file(development ? __dirname + '/development.json' : __dirname + '/production.json'); nconf.defaults({ PORT: 3000, MONGO_URI: "mongodb://localhost/local", SESSION_SECRET: "the mean stack is a very mean stack :)", NODE_ENV: "development", }); mongoose.connect(nconf.get('MONGODB_URI') || nconf.get('MONGO_URI')); mongoose.set('debug', development);
* This module is responsible of the ezPAARSE configuration parameters * it will load it from the default config.json file but these parameters * can be overrided by the user through a config.local.json file or * through the environement variables or through the command line parameter */ var nconf = require('nconf'); var path = require('path'); var envConfig = process.env.EZPAARSE_CONFIG; if (typeof envConfig === 'string' && envConfig.length > 0) { try { envConfig = JSON.parse(envConfig); } catch (e) { throw new Error('EZPAARSE_CONFIG is not a valid JSON'); } nconf.overrides(envConfig); } nconf.argv() // try to get parameter from the command line // then from the environment .env() // then from the local config .file('local', path.join(__dirname, '../config.local.json')) // then (default value) from the standard config.json file .file('default', path.join(__dirname, '../config.json')); nconf.defaults({ 'EZPAARSE_HTTP_PROXY': process.env.HTTP_PROXY || process.env.http_proxy }); // return all the captured key/values
nconf.file(configPath); } catch (e) { console.error(e); process.exit(1); } if (nconf.get('NODE_ENV') === 'test') { nconf.set('port', exampleConfig.port); nconf.set('host', exampleConfig.host); nconf.set('rippled_servers', exampleConfig.rippled_servers); } // Override `rippled_servers` with `rippled` if it exists if (/^(wss|ws):\/\/.+:[0-9]+$/.test(nconf.get('rippled'))) { nconf.overrides({ rippled_servers: [nconf.get('rippled')] }); } // check that config matches the required schema var schemaValidator = new JaySchema(); var schemaErrors = schemaValidator.validate(nconf.get(), configSchema); if (schemaErrors.length > 0) { console.error('ERROR: Invalid configuration'); console.error(JSON.stringify(formatJaySchemaErrors(schemaErrors), null, 2)); process.exit(1); } if (nconf.get('db_path')) { // Resolve absolute db_path if (nconf.get('db_path') !== ':memory:') {
var nconf = require('nconf'); var util = require('util'); var fs = require('fs'); // ### Heirarchical Config, those added first take priority. // 1. any overrides nconf.overrides({ // 'always': 'be this value' }); // 2. `process.env` // to see all environment variables, just use .env(); nconf.env(['PATH', 'conf']); // 3. `process.argv` nconf.argv(); console.log("loading config"); function getUserHome() { return process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME']; } var configFile = getUserHome() + '/.buildblinkrc'; // if(!fs.existsSync(configFile)){ // console.error("!!! No ~/.buildblinkrc file found . . . "); // } nconf.file(configFile);
'use strict'; var path = require('path'), fs = require('fs'), nconf = require('nconf'), env = process.env.NODE_ENV || 'development', root = './config/env', rootEnv = path.join(root, env); /** * Always take the environment from `process.env.NODE_ENV`, * otherwhise defaults to `development` * */ nconf.overrides({ NODE_ENV: env }); /** * Load configuration in the following order (Top values take preference): * * 1. Parse from `process.argv` * 2. Parse from `process.env` (CURRENT: ONLY NODE_ENV) * 3. Parse from environment json file * */ nconf = nconf .argv() .env(['NODE_ENV']); /**