How to use the nconf.defaults 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 mozilla / popcorn.webmaker.org / lib / config.js View on Github external
var nconf = require( "nconf" );

// 1) Look for settings from the environment
nconf.env();

// 2) Recurse up the directory tree looking for a file named "local.json"
nconf.file({ dir: __dirname, file: "local.json", search: true });

// 3) Look for settings in a file specified by an environment variable
if ( process.env.BUTTER_CONFIG_FILE ) {
  nconf.file( process.env.BUTTER_CONFIG_FILE );
}

// Load default settings from our config. Don't change this file
nconf.defaults( require( "./default-config.js" ) );

// Check for deprecated configuration options, and patch them to new equivalents if they exist
[
  {
    old: "server:bindIP"
  },
  {
    old: "server:bindPort",
    new: "PORT"
  },
  {
    old: "dirs:appHostname",
    new: "APP_HOSTNAME"
  }
].forEach(function( pref ) {
  if ( nconf.get( pref.old ) ) {
github magicshifter / MS3000-Firmware / React / FirstIteration / src / server / config.js View on Github external
// Ignore webpack custom loaders on server. todo: Reuse index.js config.
    ignore: /(\/\.|~$|\.(css|styl))/,

    // Hook ensures always fresh server response even for client file change.
    hook: true,
  },
  port: process.env.PORT || 1337,
  version: require('../../package').version,
  webpackStylesExtensions: ['css', 'less', 'sass', 'scss', 'styl'],
};

// Use above config as a default one
// Multiple other providers are available like loading config from json and more
// Check out nconf docs for fancier examples
nconf.defaults(config);

module.exports = nconf.get();
github datopian / datahub-client / lib / utils / config.js View on Github external
function setup() {
  nconf.argv()
    .env()
    .file({
      file
    })

  // This is the object that you want to override in your own local config
  nconf.defaults({
    api: 'https://api.datahub.io',
    domain: 'https://datahub.io',
    token: '',
    email: '',
    username: ''
  })
}
github sockethub / sockethub / src / config.ts View on Github external
},
    });
    nconf.env();

    // get value of flags defined by any command-line params
    const examples = nconf.get('examples');

    // Load the main config
    nconf.file(__dirname + '/../config.json');

    // only override config file if explicitly mentioned in command-line params
    nconf.set('examples:enabled', (examples ? true : nconf.get('examples:enabled')));

    // load defaults
    const defaults: object = require(__dirname + '/defaults.json');
    nconf.defaults(defaults);

    nconf.required(['platforms:whitelist', 'platforms:blacklist']);

    function defaultEnvParams(host: string, port: string | number, prop: string) {
      nconf.set(prop + ':host', host);
      nconf.set(prop + ':port', port);
    }

    defaultEnvParams(
      process.env.HOST || nconf.get('service:host'),
      process.env.PORT || nconf.get('service:port'),
      'service'
    );

    defaultEnvParams(
      process.env.REDIS_HOST || nconf.get('redis:host'),
github BMalaichik / nestjs-starter-kit / packages / backend / src / modules / config / config.providers.ts View on Github external
import * as _ from "lodash";
import * as nconf from "nconf";

import { Env } from "./config.interfaces";
import { ConfigDiToken } from "./config.di";
import { CipherService, CipherDiToken } from "../shared/cipher";


const env = process.env.NODE_ENV || Env.DEVELOPMENT;

nconf.use("memory");

nconf
    .defaults(require(`./env/config.default`))
    .overrides(require(`./env/config.${env}`))
    .argv({
        NODE_ENV: {
            default: "development",
        },
        example: {
            describe: "Example description for usage generation",
            demand: true,
            default: "some-value",
            parseValues: true,
        },
    })
    .env(["NODE_ENV"]); // set here available env variables to be loaded

export const configProvider = {
github znetstar / tor-router / test / SOCKSServer.js View on Github external
const nconf = require('nconf');
const request = require('request-promise');
const getPort = require('get-port');
const { HttpAgent, auth } = require('socksv5');
const { assert } = require('chai');
const _ = require('lodash');

const { TorPool, SOCKSServer } = require('../');
const { WAIT_FOR_CREATE, PAGE_LOAD_TIME } = require('./constants');

nconf.use('memory');
require(`${__dirname}/../src/nconf_load_env.js`)(nconf);		
nconf.defaults(require(`${__dirname}/../src/default_config.js`));

describe('SOCKSServer', function () {
	describe('#handleConnection(socket)', function () {
		let socksPort;
		let socksServerTorPool;
		let socksServer;

		before('start up server', async function (){
			socksServerTorPool = new TorPool(nconf.get('torPath'), {}, nconf.get('parentDataDirectory'), 'round_robin', null);
			socksServer = new SOCKSServer(socksServerTorPool, null, false);
	
			this.timeout(WAIT_FOR_CREATE);
	
			await socksServerTorPool.create(1);
			socksPort = await getPort();
github hackjutsu / Lepton / main.js View on Github external
function initGlobalConfigs () {
  const configFilePath = app.getPath('home') + '/.leptonrc'
  logger.info(`[conf] Looking for .leptonrc at ${configFilePath}`)
  nconf.argv().env()
  try {
    nconf.file({ file: configFilePath })
  } catch (error) {
    logger.error('[.leptonrc] Please correct the mistakes in your configuration file: [%s].\n' + error, configFilePath)
  }

  nconf.defaults(defaultConfig)  
  global.conf = nconf
}
github DaVarga / slingxdcc / lib / packdb.js View on Github external
var packdb = function packdb() {
    //defining a var instead of this (works for variable & function) will create a private definition
    var dirty = require("./dirty/dirty"),
        query = require("dirty-query").query,
        nconf = require("nconf"),
        log4js = require('log4js'),
        logger = log4js.getLogger('packdb');

    var homePath = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE;
    var appHome = homePath+'/.slingxdcc/';

    nconf.add('settings', {type: 'file', file: appHome+'config/settings.json'});

    nconf.defaults({
        "logger": {
            "packdb": appHome+"packets.db",
            "autocleandb" : true,
            "cleandb_Xminutes": 60,
            "redundantPercentage": 25,
            "removePacketsOlder_Xhours": false
        }
    });
    nconf.set('logger',nconf.get('logger'));

    nconf.save();

    var packDb = dirty.Dirty(nconf.get('logger:packdb'));


    packDb.on('load', function () {
github ediardo / kmdr-cli / index.js View on Github external
import cli from 'commander';
import nconf from 'nconf';
import os from 'os';
import path from 'path';
import shelljs from 'shelljs';
import { GraphQLClient } from 'graphql-request';
import { prompt } from 'inquirer';

nconf.file(path.join(os.homedir(), '.kommandrrc'));
nconf.defaults({
  user: 'anon',
});

const version = '0.0.1';

const graphqlClient = new GraphQLClient('http://localhost:5001/graphql', {
  headers: {
    authorization: 'token',
    'User-agent': `kommandr-cli ${version}`,
    username: nconf.get('user'),
    token: nconf.get('token'),
  }
});
github polonel / trudesk / app.js View on Github external
function loadConfig() {
    nconf.file({
        file: configFile
    });

    nconf.defaults({
        base_dir: __dirname
    });
}

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