node_modules/config-js/index.js
/**
 * Config provides a simple read-only API to a configuration object.
 * @param {String} pathToConfigFile The configuration file
 * @param {String} [region] Optional indicator for the current region, e.g. 'en'
 */
Config provides a simple read-only API to a configuration object.
@param {String} pathToConfigFile The configuration file
@param {String} [region] Optional indicator for the current region, e.g. 'en'
Config provides a simple read - only API to a configuration object . @param { String } pathToConfigFile The configuration file @param { String } [ region ] Optional indicator for the current region e . g . ' en '
function Config(pathToConfigFileIn, region) {
    have(arguments, {pathToConfigFile: 'str', region: 'opt str' });
    debug('pathToConfigFileIn: '+pathToConfigFileIn);
    var pathToConfigFile = pathToConfigFileIn;
    var idx = pathToConfigFileIn.indexOf('##');
    if (idx > -1 && is.nonEmptyStr(process.env.NODE_ENV)) {
        pathToConfigFile = pathToConfigFileIn.substr(0, idx) +
            process.env.NODE_ENV + pathToConfigFileIn.substr(idx+2);
    }
    if (!is.nonEmptyStr(pathToConfigFile))
        throw new Error('Bad path to config file: '+pathToConfigFile);
    if (!fs.existsSync(pathToConfigFile))
        throw new Error('Config file is missing: '+pathToConfigFile);
    if (is.defined(region))  assert.ok(is.nonEmptyStr(region));
    if (is.undefined(region)) region = 'en';
    debug('## sub: pathToConfigFileIn: '+pathToConfigFileIn);
    this.pathToDefaults = path.join(path.dirname(pathToConfigFileIn),
                                    'defaults.js');
    this.pathToConfigFile = pathToConfigFile;
    debug('region: '+region);
    this.region = region;
    var self = this;
    debug('pathToDeafults: '+this.pathToDefaults);
    fs.watchFile(this.pathToConfigFile, {persistent: false}, function () {
        self.loadConfig(self.pathToDefaults, self.pathToConfigFile, self.region);
    });
    this.loadConfig(self.pathToDefaults, self.pathToConfigFile, self.region);
    var util = require('util');
    debug('Config: '+util.inspect(this.configObj));
}
function Config ( pathToConfigFileIn , region ) { have ( arguments , { pathToConfigFile : 'str' , region : 'opt str' } ) ; debug ( 'pathToConfigFileIn: ' + pathToConfigFileIn ) ; var pathToConfigFile = pathToConfigFileIn ; var idx = pathToConfigFileIn . indexOf ( '##' ) ; if ( idx > - 1 && is . nonEmptyStr ( process . env . NODE_ENV ) ) { pathToConfigFile = pathToConfigFileIn . substr ( 0 , idx ) + process . env . NODE_ENV + pathToConfigFileIn . substr ( idx + 2 ) ; } if ( ! is . nonEmptyStr ( pathToConfigFile ) ) throw new Error ( 'Bad path to config file: ' + pathToConfigFile ) ; if ( ! fs . existsSync ( pathToConfigFile ) ) throw new Error ( 'Config file is missing: ' + pathToConfigFile ) ; if ( is . defined ( region ) ) assert . ok ( is . nonEmptyStr ( region ) ) ; if ( is . undefined ( region ) ) region = 'en' ; debug ( '## sub: pathToConfigFileIn: ' + pathToConfigFileIn ) ; this . pathToDefaults = path . join ( path . dirname ( pathToConfigFileIn ) , 'defaults.js' ) ; this . pathToConfigFile = pathToConfigFile ; debug ( 'region: ' + region ) ; this . region = region ; var self = this ; debug ( 'pathToDeafults: ' + this . pathToDefaults ) ; fs . watchFile ( this . pathToConfigFile , { persistent : false } , function ( ) { self . loadConfig ( self . pathToDefaults , self . pathToConfigFile , self . region ) ; } ) ; this . loadConfig ( self . pathToDefaults , self . pathToConfigFile , self . region ) ; var util = require ( 'util' ) ; debug ( 'Config: ' + util . inspect ( this . configObj ) ) ; }
Config provides a simple read-only API to a configuration object.
Config provides a simple read - only API to a configuration object .
// if the path has '##' and process.env.NODE_ENV is a non-empty string, // replace '##' with the contents of process.env.NODE_ENV // complimentary to have arg checking // english is the default // set a watch for when the file changes, to reload the file. // we can't wait for the file to change to re-load, so we load it now