I am currently working on optimizing the performance of my express application for production. I came across a helpful video tutorial at https://www.youtube.com/watch?v=WiZ2Py97rio, where the presenter explains a config object with keys for 'development', 'production' & 'test'.
Following the example in the video, I created a similar configuration:
import bunyan from "bunyan";
const loggers = {
development: () => bunyan.createLogger({name: "development", level: "debug"}),
production: () => bunyan.createLogger({name: "production", level: "info"}),
test: () => bunyan.createLogger({name: "test", level: "fatal"}),
}
const config = {
development: {
log: loggers.development
},
production: {
log: loggers.production
},
test: {
log: loggers.test
}
};
export default config;
However, when attempting to implement this configuration, it seems to only work in development mode:
import configObject from "./config.js";
const config = configObject[process.env.NODE_ENV || "development"];
const log = config.log();
In production, running the following code yields unexpected results:
console.log(process.env.NODE_ENV || "development");
console.log(configObject);
console.log(configObject[process.env.NODE_ENV || "development"]);
The output is as follows:
production
{
development: { log: [Function: development] },
production: { log: [Function: production] },
test: { log: [Function: test] }
}
undefined
Although it correctly identifies the environment as production and has the 'production' key in the config object, it fails to evaluate properly. Any insights on why this might be happening would be greatly appreciated.
Thank you in advance!