API Reference

debug

Tiny JavaScript debugging utility that prints namespaced messages gated by the DEBUG environment variable at runtime.

Official Documentation ↗
CompatibilityThis documentation covers version v4.3. Check the official docs for the latest API surface.

Installation

npmnpm install debug

Methods

debug writes to stderr only when the namespace matches the DEBUG environment variable, keeping production logs quiet.

Key Features

  • Zero configuration namespaced logging
  • Wildcard namespace enabling like app:*
  • Color coding and millisecond deltas per namespace

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

API reference evidence

Fetched from official sources on 2026-11-08T19:23:00+08:00 via PowerShell Invoke-WebRequest https://raw.githubusercontent.com/debug-js/debug/master/src/common.js(函数定义);PowerShell Invoke-WebRequest https://raw.githubusercontent.com/debug-js/debug/master/README.md(用法).

FAQ

Why is nothing printed?
debug writes only when the DEBUG environment variable matches the namespace. Run with DEBUG=app:* node server.js to see output.
Does debug write to stdout?
No. It writes to stderr so structured stdout pipelines are not polluted, which matters when piping JSON between processes.
How do I disable it in production?
Leave the DEBUG variable unset. The check is a single in-memory boolean, so the disabled path is effectively free.