Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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, {persistent: false}, 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