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:
check_node_env.js
if(process.env.NODE_ENV == "development") {
// TODO your code goes here
}
or
example.js
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.
Check out similar posts by category:
Javascript, NodeJS
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow