🛠️
Utility200M+/wkMIT

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
npm install debug
yarn
yarn add debug
pnpm
pnpm add debug

Import

ESM
import createDebug from 'debug';

Quick Example

usage
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.js

About 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

Packagedebug
CategoryUtility
Weekly Downloads200M+
LicenseMIT
Installnpm install debug

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.