How to use config - 10 common examples

To help you get started, we’ve selected a few config 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 / addons-frontend / tests / unit / helpers.js View on Github external
export const getFakeConfig = (
  params = {},
  { allowUnknownKeys = false } = {},
) => {
  for (const key of Object.keys(params)) {
    if (!config.has(key) && !allowUnknownKeys) {
      // This will help alert us when a test accidentally relies
      // on an invalid config key.
      throw new Error(
        `Cannot set a fake value for "${key}"; this key is invalid`,
      );
    }
  }
  return Object.assign(config.util.cloneDeep(config), params);
};
github Automattic / wp-calypso / server / bundler / sections-loader.js View on Github external
include = include.split( ',' );
		}
		console.log( `[sections-loader] Limiting build to ${ include.join( ', ' ) } sections` );
		const allSections = sections;
		sections = allSections.filter( section => include.includes( section.name ) );
		if ( ! sections.length ) {
			// nothing matched. warn.
			console.warn( `[sections-loader] No sections matched ${ include.join( ',' ) }` );
			console.warn( `[sections-loader] Available sections are:` );
			printSectionsAndPaths( allSections );
		}
	}

	return addModuleImportToSections( {
		sections,
		shouldSplit: config.isEnabled( 'code-splitting' ) && ! forceRequire,
		onlyIsomorphic,
	} );
};
loader.addModuleImportToSections = addModuleImportToSections;
github joeferner / redis-commander / bin / healthcheck.js View on Github external
#!/usr/bin/env node

'use strict';

// fix the cwd to project base dir for browserify and config loading
let path = require('path');
process.chdir( path.join(__dirname, '..') );

const config = require('config');
const http = require('http');

let port = (config.has('server.port') ? config.get('server.port') : null) || '127.0.0.1';
let host = (config.has('server.address') ? config.get('server.address') : null);
if (!host || host === '0.0.0.0' || host === '::') host =  '127.0.0.1';
let urlPrefix = (config.has('server.urlPrefix') ? config.get('server.urlPrefix') : null) ||'';

http.get(`http://${host}:${port}${urlPrefix}/healthcheck`, (resp) => {
  let data = '';

  resp.on('data', (chunk) => {
    data += chunk;
  });

  // The whole response has been received. Print out the result.
  resp.on('end', () => {
    if (data.trim() === 'ok') process.exit(0);
    else {
      console.log('got unexprected response from server: ' + data);
github fzaninotto / screenshot-as-a-service / app.js View on Github external
process.on('SIGINT', function () {
  process.exit(0);
});

// web service
var app = express();
app.configure(function(){
  app.use(express.static(__dirname + '/public'))
  app.use(app.router);
  app.set('rasterizerService', new RasterizerService(config.rasterizer).startService());
  app.set('fileCleanerService', new FileCleanerService(config.cache.lifetime));
});
app.configure('development', function() {
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
require('./routes')(app, config.server.useCors);
app.listen(config.server.port, config.server.host);
console.log('Express server listening on ' + config.server.host + ':' + config.server.port);
github DivanteLtd / vue-storefront / core / scripts / server.js View on Github external
function invalidateCache (req, res) {
  if (config.server.useOutputCache) {
    if (req.query.tag && req.query.key) { // clear cache pages for specific query tag
      if (req.query.key !== config.server.invalidateCacheKey) {
        console.error('Invalid cache invalidation key')
        apiStatus(res, 'Invalid cache invalidation key', 500)
        return
      }
      console.log(`Clear cache request for [${req.query.tag}]`)
      let tags = []
      if (req.query.tag === '*') {
        tags = config.server.availableCacheTags
      } else {
        tags = req.query.tag.split(',')
      }
      const subPromises = []
      tags.forEach(tag => {
        if (config.server.availableCacheTags.indexOf(tag) >= 0 || config.server.availableCacheTags.find(t => {
          return tag.indexOf(t) === 0
        })) {
          subPromises.push(cache.invalidate(tag).then(() => {
            console.log(`Tags invalidated successfully for [${tag}]`)
          }))
        } else {
          console.error(`Invalid tag name ${tag}`)
        }
      })
      Promise.all(subPromises).then(r => {
github sirodoht / aspen / back / app.js View on Github external
.catch((err) => {
      console.log('Passport error:', err);
      done(err);
    });
}
));

app.use(cors());

app.use(router.routes());

app.use(static(path.join(__dirname, '../front/static')));

app.use(favicon(path.join(__dirname, '../front/static/favicon.ico')));

const port = process.env.PORT || config.port;

// models.sequelize.sync({ force: true })
models.sequelize.sync()
  .then(() => {
    app.listen(port);
    app.on('error', (error) => {
      console.error('App error:', error);
      process.exit(1);
    });
    console.log(`Server running on port ${port}`);
  });
github DivanteLtd / storefront-api / scripts / db.js View on Github external
const program = require('commander')
const config = require('config')
const common = require('../migrations/.common')
const es = require('../src/lib/elastic')

program
  .command('rebuild')
  .option('-i|--indexName ', 'name of the Elasticsearch index', config.elasticsearch.indices[0])
  .action((cmd) => { // TODO: add parallel processing
    if (!cmd.indexName) {
      console.error('error: indexName must be specified');
      process.exit(1);
    }

    console.log('** Hello! I am going to rebuild EXISTING ES index to fix the schema')
    const originalIndex = cmd.indexName
    const tempIndex = originalIndex + '_' + Math.round(+new Date() / 1000)

    console.log(`** Creating temporary index ${tempIndex}`)
    es.createIndex(common.db, tempIndex, '', (err) => {
      if (err) {
        console.log(err)
      }
github joeferner / redis-commander / bin / redis-commander.js View on Github external
appInstance.listen(config.get('server.port'), config.get('server.address'), function() {
    console.log(`listening on ${config.get('server.address')}:${config.get('server.port')}`);

    // default ip 0.0.0.0 and ipv6 equivalent cannot be opened with browser, need different one
    // may search for first non-localhost address of server instead of 127.0.0.1...
    let address = '127.0.0.1';
    if (config.get('server.address') !== '0.0.0.0' && config.get('server.address') !== '::') {
      address = config.get('server.address');
    }
    let msg = `access with browser at http://${address}:${config.get('server.port')}`;
    if (urlPrefix) {
      console.log(`using url prefix ${urlPrefix}`);
      msg += urlPrefix;
    }
    console.log(msg);
  });
}
github VertigoRay / GDAXBot / strategies / stddev.js View on Github external
addTrades(trades) {
		for (let trade in trades) {
			// console.log('add trade price:', parseFloat(trades[trade].price.toString()))
			this.trade_prices.push(parseFloat(trades[trade].toString()));

			while (this.trade_prices.length > settings.get(`${this.product_id}.strategies.StdDev.trades_n`)) {
				this.trade_prices.shift();
			}
		}
	}
github davidmerfield / Blot / scripts / user / create.js View on Github external
User.generateAccessToken(email, function(err, token) {
    if (err) throw err;

    // The full one-time log-in link to be sent to the user
    var url = format({
      protocol: "https",
      host: config.host,
      pathname: "/sign-up",
      query: {
        already_paid: token
      }
    });

    console.log("Use this link to create an account for:", email);
    console.log(url);
    callback();
  });
}