Node.js: Check if you are in debug or production mode

Sometimes you have to use other values in a variable when your application is in production as if when you are debugging it.
For example you have to use another web service URL.

Here is how can do it:

var webApiUrl;

if (process.env.NODE_ENV === "production") {
	// use in production
	webApiUrl = "";
else {
	// use on debugging
	webApiUrl = "/api";

If you do it like me and use Webpack, you can start the debug mode with webpack -d and the production mode with webpack -p.

Leave a comment