Skip to content

Instantly share code, notes, and snippets.

@zodman
Forked from GochoMugo/intro.md
Created June 6, 2020 03:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save zodman/01f67753ec3af5d1a2b18ee8e1955e0b 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