Shoulder.dev Logo Shoulder.dev

The Big Picture - benhall/express-demo - Debug

Debug is a lightweight JavaScript debugging utility that can be used in Node.js and web browsers to toggle debug output for different parts of your application. It allows you to easily identify and fix issues by logging debug statements and providing color-coded output for better visual parsing.

To use Debug, first install it using npm by running npm install debug in your terminal. Once installed, require it in your JavaScript file and pass it the name of your module to get a decorated version of console.error. For example:

const debug = require('debug')('yourModuleName');

// ... your code here ...

debug('This is a debug statement');

You can also use multiple debuggers within the same file by assigning different names to each one.

To enable or disable debug output, set the DEBUG environment variable to the name of the module or modules you want to debug, separated by commas. For example:

# To enable debug output for yourModuleName
DEBUG=yourModuleName node yourFile.js

# To disable debug output for yourModuleName
DEBUG=* node yourFile.js

Debug also supports showing the time difference between debug statements and has conventions for naming debuggers in libraries. It can be used in web browsers by building it using browserify or using the browserify-as-a-service build, and supports outputting to different streams.

Debug is a powerful and flexible debugging utility that can help you efficiently identify and fix issues in your Node.js and web applications.