The debug module for Node.js is one of the most useful utilities when it comes to high-level debugging. The only problem with using it, would that the module eventually becomes a hard dependency in your project. Your project will NOT run if the package is not installed despite the fact that it is only needed in development mode.
One way to work around this to have a dummy function used in place of the real debug function, when users are in production mode.
var debug = process.env.DEBUG ? require("debug")("MyProject:Server") : function() {};
This way, the module is only loaded when the DEBUG environment variable is set. Therefore, the package can be added as a devDependency
to the project's package.json
rather than as a dependency
.