Files
legolog/src/config.js
Ben f68e7df223 bro
Former-commit-id: ccc7bc8c7bf361055c0a021fdad567a1e62f3ed3
2022-02-08 18:01:10 +00:00

28 lines
913 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: load
}