The `debug` package is a lightweight and highly popular debugging utility designed for both Node.js and web browser environments. Currently stable at version `4.4.3`, it maintains a regular release cadence with frequent patch and minor updates addressing bug fixes and minor enhancements. Its core functionality revolves around providing a simple, namespace-based logging mechanism that allows developers to selectively enable or disable debug output for different parts of an application using the `DEBUG` environment variable (or `localStorage` in browsers). Key differentiators include its minimal footprint, automatic colorized output in supported terminals and browser developer tools, and the useful millisecond difference displayed between consecutive log calls, aiding in performance analysis. The project recently migrated its repository from `visionmedia/debug` to `debug-js/debug`. It is crucial to note that version `4.4.2` was compromised and users should upgrade immediately to `4.4.3` or later to avoid potential security risks.
npm install debugVerified import paths — ran on the pinned version, not inferred.
Demonstrates creating multiple debugger instances with different namespaces and enabling them via the `DEBUG` environment variable.
Upgrade to `debug@4.4.3` or a later stable version. Review your `package-lock.json` or `yarn.lock` to ensure `4.4.2` is not being pulled in by transitive dependencies.
Migrate your `.enable()` calls from regexes to glob patterns (e.g., `*`, `-`). For instance, `debug.enable('foo:*|bar:*')` instead of `debug.enable(/(foo|bar):.*/)`. Regex functionality will not be re-added.Install `supports-color` as a dependency: `npm install supports-color`.
On CMD: `set DEBUG=* & node app.js`. On PowerShell: `$env:DEBUG='*'; node app.js`. On Linux/macOS: `DEBUG='*' node app.js`.
Upgrade `debug` to `4.3.6` or later to benefit from internal fixes. Modernize your own codebase to use `String.prototype.substring()` or `slice()` instead of `substr()`, and named capture groups for regexes.
Ensure the `DEBUG` environment variable is correctly set before running your application. For example, `DEBUG='my-app:*' node app.js` (Linux/macOS), `set DEBUG=my-app:* & node app.js` (Windows CMD), or `$env:DEBUG='my-app:*'; node app.js` (Windows PowerShell).
Always call `require('debug')` or `import debug from 'debug'` with a namespace string. Correct: `const myDebug = require('debug')('my-namespace'); myDebug('hello');`Install `supports-color` (`npm install supports-color`) and ensure your Node.js application is running in an environment where `process.stderr` is a TTY (e.g., directly in a terminal, not piped to a file).