Skip to content

Instantly share code, notes, and snippets.

@wmantly
Last active January 25, 2018 20:57
Show Gist options
  • Select an option

  • Save wmantly/1283bbffca25d92bc0b84dac106b1e9c to your computer and use it in GitHub Desktop.

Select an option

Save wmantly/1283bbffca25d92bc0b84dac106b1e9c to your computer and use it in GitHub Desktop.
'use strict';
const app = require('../app');
const extend = require('extend');
function load(filePath, required){
try {
return require(filePath);
} catch(error){
if(error.name === 'SyntaxError'){
console.error(`Loading ${filePath} file failed!\n`, error.message);
process.exit(1);
} else if (error.code === 'MODULE_NOT_FOUND'){
console.warn(`NO ${filePath} FILE FOUND! This may cause issues...`);
if (required){
process.exit(1);
}
return {};
}else{
console.dir(`Unknown error in loading ${filePath} config file.\n`, error);
}
}
};
module.exports = extend(
true, // enable deep copy
load('./default', true),
load(`./${app.locals.settings.env}`),
load('./secrets')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment