Sunday, 4 June 2017

Only show logging info in dev-mode in NodeJS/Browser

I have a javascript class which can be used in both the browser and NodeJS.

Suppose the class looks like this

class BarFoo {
    lookup() {
         // Do magic
         if (magicFailed && window.DEVELOP) {
             console.log('Show some info to help debugging...');
         }
    }
    ...
}

To make this example also work for NodeJS I can imaging that the global In this example I only show the log message if the app is in developing mode (window.DEVELOP === true). But I would like to use this class also in a nodeJS app, so I don't have a window object. What is the preferred way to set this up for both?



via Jeanluca Scaljeri

No comments:

Post a Comment