index.js
function Config(pathToConfigFileIn, region) {
    have(arguments, {pathToConfigFile: 'str', region: 'opt str' });
    debug('pathToConfigFileIn: '+pathToConfigFileIn);

    // if the path has '##' and process.env.NODE_ENV is a non-empty string,
    // replace '##' with the contents of process.env.NODE_ENV
    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);
    }

    // complimentary to have arg checking
    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));

    // english is the default
    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);

    // set a watch for when the file changes, to reload the file.
    fs.watchFile(this.pathToConfigFile, function () {
        self.loadConfig(self.pathToDefaults, self.pathToConfigFile, self.region);
    });

    // we can't wait for the file to change to re-load, so we load it now
    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);

    // if the path has '##' and process.env.NODE_ENV is a non-empty string,
    // replace '##' with the contents of process.env.NODE_ENV
    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);
    }

    // complimentary to have arg checking
    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));

    // english is the default
    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);

    // set a watch for when the file changes, to reload the file.
    fs.watchFile(this.pathToConfigFile, function () {
        self.loadConfig(self.pathToDefaults, self.pathToConfigFile, self.region);
    });

    // we can't wait for the file to change to re-load, so we load it now
    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 ) ; // if the path has '##' and process.env.NODE_ENV is a non-empty string, // replace '##' with the contents of process.env.NODE_ENV 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 ) ; } // complimentary to have arg checking 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 ) ) ; // english is the default 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 ) ; // set a watch for when the file changes, to reload the file. fs . watchFile ( this . pathToConfigFile , function ( ) { self . loadConfig ( self . pathToDefaults , self . pathToConfigFile , self . region ) ; } ) ; // we can't wait for the file to change to re-load, so we load it now 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.
@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 .