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 = "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.

LGK Blog

I’m a web developer, so you’ll primarily find posts about coding but also about design (UX/UI) on my Medium site.

Lars Gerrit Kliesing / LGK

Written by

I’m a web developer, so you’ll primarily find posts about coding but also about design (UX/UI) on my Medium site.

LGK Blog

LGK Blog

I’m a web developer, so you’ll primarily find posts about coding but also about design (UX/UI) on my Medium site.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade