How to check NODE_ENV environment variable in Node.JS
You can use process.env.NODE_ENV
to check the value of the NODE_ENV
environment variable in Node.JS:
if(process.env.NODE_ENV == "development") {
// TODO your code goes here
}
or
if(process.env.NODE_ENV == "production") {
// TODO your code goes here
}
Note that by defaultĀ NODE_ENV
isĀ undefined
so remember to handle that case appropriately.