Skip to content

Instantly share code, notes, and snippets.

@GochoMugo
Last active October 14, 2020 20:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save GochoMugo/09f70c4278ede0f53305 to your computer and use it in GitHub Desktop.
Save GochoMugo/09f70c4278ede0f53305 to your computer and use it in GitHub Desktop.
Node.js Debug Package as a Dev-Dependency

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment