Basically, I am using morgan to look at logs in developement. I have it under --save-dev
. But in my app.js
I use const morgan = require('morgan');
. It runs fine on my local machine but I only use morgan depending on NODE_ENV
. How can I make it that it doesnt raise a module not found exception in production? I will not be using it there so I have it in dev dependencies. Do I have to manually remove that line every time I deploy? Thanks :-)
You can try something like:
if(NODE_ENV !== 'production') {
const morgan = require('morgan');
app.use(morgan(...))
}
I just wrote a similar code snippet and ran into no issues.
You can just check the NODE_ENV
environment variable in your code via the process.env
object Node provides:
if(process.env.NODE_ENV !== 'production') const morgan = require('morgan');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With