should i install morgan as a normal dependency
or as devDependency
since I'm not gonna use the logging in production mode anyway:
if (config.NODE_ENV !== 'production') {
app.use(morgan('dev', { stream: { write: message => logger.http(message) } }));
}
Assuming that
config.NODE_ENV
matches theprocess.env.NODE_ENV
and that you installed vianpm install --production
or similar, then you don't need to includemorgan
in yourdependencies
and can just have it indevDependencies
. You should move therequire
orimport
inside the if statement to prevent errors. When you callrequire
orimport
is when it tries to load fromnode_modules
or the module cache if it was already loaded.That said, I would personally include it in the
dependencies
and disable logging via a config setting in case I wanted to enable logging in my production environment to debug something.