How to use nconf - 10 common examples

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 hyperledger / fabric-sdk-node / test / unit / client.js View on Github external
test('\n\n ** Config **\n\n', (t) => {
	// setup the environment
	process.argv.push('--test-4=argv');
	process.argv.push('--test-5=argv');
	process.env.TEST_3 = 'env';
	process.env.test_6 = 'mapped';
	// internal call. clearing the cached config.
	if (global && global.hfc) global.hfc.config = undefined;
	require('nconf').reset();

	t.equals(Client.getConfigSetting('request-timeout', 'notfound'), 45000, 'checking that able to get "request-timeout" value from an additional configuration file');
	//try adding another config file
	Client.addConfigFile(path.join(__dirname, '../fixtures/local.json'));
	t.equals(Client.getConfigSetting('test-2', 'notfound'), 'local', 'checking that able to test-2 value from an additional configuration file');
	t.equals(Client.getConfigSetting('test-3', 'notfound'), 'env', 'checking that test-3 environment values are used');
	t.equals(Client.getConfigSetting('test-4', 'notfound'), 'argv', 'checking that test-4 argument values are used');
	Client.setConfigSetting('test-5', 'program');
	t.equals(Client.getConfigSetting('test-5', 'notfound'), 'program', 'checking that test-5 program values are used');
	t.equals(Client.getConfigSetting('test-6', 'notfound'), 'mapped', 'checking that test-6 is enviroment mapped value');
	t.end();
});
github Gravebot / Gravebot / tests / index.js View on Github external
import glob from 'glob';
import nconf from 'nconf';
import R from 'ramda';

import '../src/init-config';
import '../src/redis';
import startExpress from '../src/express';
import { init as initPhantom } from '../src/phantom';


// Defaults
startExpress();
initPhantom();
nconf.set('CLIENT_ID', '123');

const glob_options = {
  realpath: true,
  nodir: true
};

const test_files = R.flatten([
  glob.sync('./tests/*/*.js', glob_options),
  glob.sync('./tests/*(!(index.js))', glob_options)
]);

R.forEach(test_case => require(test_case), test_files);
github wildbit / postmark.js / tests / fixture_generalClientTests.js View on Github external
var mocha = require('mocha');
var assert = require('assert');
var nconf = require('nconf');
var testingKeys = nconf.env().file({
    file: __dirname + '/../testing_keys.json'
});
var util = require('util');
var merge = require('merge');

var postmark = require('../lib/postmark/index.js');

describe('general client functionality', function() {
    // allow some of the more intensive tests to take longer.
    this.timeout(30000);
    var _client = null;

    beforeEach(function() {
        _client = new postmark.Client(testingKeys.get('WRITE_TEST_SERVER_TOKEN'));
    });
github wildbit / postmark.js / tests / fixture_postmarkClientSending.js View on Github external
'use strict';

var mocha = require('mocha');
var assert = require('assert');
var nconf = require('nconf');
var testingKeys = nconf.env().file({
  file: __dirname + '/../testing_keys.json'
});
var util = require('util');
var merge = require('merge');

var postmark = require('../lib/postmark/index.js');

describe('client email sending', function() {
  // allow some of the more intensive tests to take longer.
  this.timeout(30000);
  var _client = null;
  var testTemplateAlias = 'postmark-js-batch-testing template';

  beforeEach(function() {
    _client = new postmark.Client(testingKeys.get('WRITE_TEST_SERVER_TOKEN'));
    _client.deleteTemplate(testTemplateAlias);
github Azard / egg-oauth2-server / test / fixtures / apps / oauth2-server-test / app / extend / oauth.js View on Github external
module.exports = app => {

  // Mock Data
  nconf.use('file', {
    file: path.join(app.config.baseDir, 'app/mock/db.json'),
  });

  class Model {
    constructor(ctx) {
      this.ctx = ctx;
    }

    async getClient(clientId, clientSecret) {
      const client = nconf.get('client');
      if (clientId !== client.clientId || clientSecret !== client.clientSecret) {
        return;
      }
      return client;
    }
github kalamuna / kalastatic / test / index.js View on Github external
return new Promise((resolve, reject) => {
      // Create the configuration for the test.
      const conf = new nconf.Provider()

      // Force the settings for the test.
      const testOpts = {
        base: path.join('test', 'fixtures', name)
      }
      extend(testOpts, opts)
      conf.overrides(testOpts)

      // Create the environment.
      const kalastatic = new KalaStatic(conf)
      kalastatic.build().then(() => {
        // Make sure the build passes.
        const base = kalastatic.nconf.get('base')
        const build = path.join(base, kalastatic.nconf.get('destination'))
        const expected = path.join(base, 'expected')
        assertDir(build, expected)
github ElevenGiants / eleven-server / test / func / data / rpc.js View on Github external
rpc.__get__('initServer')(function serverStarted() {
				// meddle with base port to get a loopback client in worker process
				require('nconf').overrides({net: {rpc: {basePort: 17001}}});
				rpc.__get__('initClient')(GSCONF_LOOPBACK, function clientStarted() {
					// make fake client RPC connection available under our own GSID
					rpc.__get__('clients')['gs01-02'] =
						rpc.__get__('clients')['gs01-loopback'];
					done();
				});
				require('nconf').overrides({});  // reset
			});
		});
github codius-deprecated / codius-cli / bin / codius-cli.js View on Github external
ANY  SPECIAL ,  DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
    WHATSOEVER  RESULTING  FROM  LOSS  OF USE, DATA OR PROFITS, WHETHER IN AN
    ACTION  OF  CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

var winston = require('winston');
var nconf = require('nconf');
var Codius = require('../lib/codius').Codius;
var Config = require('../lib/config').Config;

winston.cli();

// Use nconf to load command line arguments and environment variables
nconf.argv()
     .env()
     .file({ file: 'HOME/.config/codius/cli.json' });
var config = new Config(nconf.get());
var command = nconf.get('_')[0];

if (config.config.debug) {
  winston.default.transports.console.level = 'debug';
}

var codius = new Codius();
codius.load(config).then(function () {
  codius.runCommand(command);
}).catch(function (err) {
  console.error(err.stack ? err.stack : err);
  process.exit(1);
}).done();
github tracking-exposed / facebook / bin / content.js View on Github external
const Promise = require('bluebird');
const debug = require('debug')('fbtrex:content');
const nconf = require('nconf');
const cors = require('cors');

/* this is the same struct of the previous version */
const mongo = require('../lib/mongo');
const common = require('../lib/common');
const security = require('../lib/security');

var cfgFile = "config/content.json";
nconf.argv().env().file({ file: cfgFile })

if(nconf.get('FBTREX') !== 'production') {
    debug("Because $FBTREX is not 'production', it is assumed be 'development'");
    nconf.stores.env.readOnly = false;
    nconf.set('FBTREX', 'development');
    nconf.stores.env.readOnly = true;
} else {
    debug("Production execution!");
}

debug("configuration file: %s | FBTREX mode [%s]", cfgFile, nconf.get('FBTREX'));

if(!nconf.get('interface') || !nconf.get('port') ||  !nconf.get('schema') ) {
    console.log("Missing configuration essential (interface, post, schema)");
    process.exit(1);
}

/* configuration for elasticsearch */
const echoes = require('../lib/echoes');
echoes.addEcho("elasticsearch");
github mrvautin / adminMongo / app.js View on Github external
console.log(err.stack);
    res.status(err.status || 500);
    res.render('error', {
        message: err.message,
        error: {},
        helpers: handlebars.helpers
    });
});

app.on('uncaughtException', function(err){
    console.error(err.stack);
    process.exit();
});

// add the connections to the connection pool
var connection_list = nconf.stores.connections.get('connections');
var connPool = require('./connections');
var monitoring = require('./monitoring');
app.locals.dbConnections = null;

async.forEachOf(connection_list, function (value, key, callback){
    var MongoURI = require('mongo-uri');

    try{
        MongoURI.parse(value.connection_string);
        connPool.addConnection({connName: key, connString: value.connection_string, connOptions: value.connection_options}, app, function (err, data){
            if(err)delete connection_list[key];
            callback();
        });
    }catch(err){
        callback();
    }

nconf

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

MIT
Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis