debug
debug is a tiny JavaScript debugging utility modeled after Node.js core's debugging technique, providing namespaced debug output that can be selectively enabled…
Installation
npm install debug
yarn add debug
pnpm add debug
Import
import createDebug from 'debug';
Quick Example
import createDebug from 'debug';
const debug = createDebug('app:server');
debug('Server starting on port %d', 3000);
debug('Request: %O', { method: 'GET', path: '/' });
// Enable with: DEBUG=app:server node app.jsAbout debug
debug is a tiny JavaScript debugging utility modeled after Node.js core's debugging technique, providing namespaced debug output that can be selectively enabled through environment variables. The library creates debug functions bound to a namespace (e.g., debug('app:server'), debug('app:db')), and output is only displayed when the DEBUG environment variable matches the namespace pattern. This allows developers to embed extensive debug logging throughout an application that produces zero output in production, then selectively enable specific namespaces during development or troubleshooting with patterns like DEBUG=app:server,app:db or DEBUG=app:*. Each namespace is automatically assigned a distinct color for visual identification in terminal output, and output includes millisecond timestamps showing time elapsed since the last debug call for the same namespace. debug works in both Node.js and browsers — in browsers, it uses localStorage instead of environment variables. The library is used by thousands of popular packages including Express, Mocha, Socket.IO, Babel, and Koa for internal debugging output. The convention of using colon-separated namespaces (library:component) has become a standard pattern in the Node.js ecosystem.
Quick Facts
| Package | debug |
| Category | Utility |
| Weekly Downloads | 200M+ |
| License | MIT |
| Install | npm install debug |
Related Packages
Winston is the most popular logging library for Node.js, designed to be a simple and universal loggi…
Pino is an extremely fast Node.js logger that outputs newline-delimited JSON (NDJSON) with minimal o…
Morgan is an HTTP request logger middleware for Node.js that records incoming request details in a c…
Chalk is the most popular library for styling terminal string output with colors and formatting in N…
Browse npm Packages by Category
Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.