Files
legolog/src/config.js
Ben 944ac209f0 setup
Former-commit-id: 9072f7b9342c8edc6f1da22555d2ea8585906ff0
2022-04-10 00:22:42 +01:00

28 lines
882 B
JavaScript

const Logger = require('./logger.js');
const dotenv = require('dotenv');
function Load() {
Logger.Info('Loading Config...');
const res = dotenv.config();
Logger.Debug(`CONFIG: ${JSON.stringify(res.parsed)}`);
Logger.Debug(`CONFIG: running in ${res.parsed.NODE_ENV} mode`);
// if NODE_ENV is dev, every config item that is dev is made into the actual one so that the
// individual modules do not need to care about hte mode of operation
if (res.parsed.NODE_ENV === 'dev') {
Object.keys(res.parsed).forEach(key => {
if (key.endsWith('_DEV')) {
const newKey = key.substring(0, key.length - 4);
process.env[newKey] = res.parsed[key];
Logger.Debug(`CONFIG KEY: '${newKey}' DEVELOPMENT VALUE: '${process.env[newKey]}'`);
}
});
}
}
module.exports = {
Load,
};