Node.js: Check if you are in debug or production mode
Jul 26, 2017 · 1 min read
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 = "http://myapp.online/awesome-app/api"; } 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.
Originally published at blog.lgk.io.

