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.

6 Kommentare

  1. I enjoy what you guys are up too. Such clever work and coverage!
    Keeep up the awesome works guys I’ve included you guys tto my pwrsonal blogroll.

  2. Spot on with this write-up, I truly feel this website needs
    far more attention. I’ll probably be back again to see more, thanks for the information!

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.