node:diagnostics_channel

Node.js diagnostics_channel module, resolvable via both ESM import and CommonJS require. Implemented as a guest-JavaScript shim providing named publish/subscribe channels and tracing channels.

javascript
import diagnostics_channel from "node:diagnostics_channel";

const ch = diagnostics_channel.channel("my.app.request");
ch.subscribe((message, name) => console.log(name, message));
if (ch.hasSubscribers) ch.publish({ path: "/" });

Implemented surface

ExportDescription
channel(name)Get (or create) the named Channel.
hasSubscribers(name)Whether the named channel has subscribers.
subscribe(name, onMessage)Subscribe to a channel by name.
unsubscribe(name, onMessage)Remove a subscription.
tracingChannel(nameOrChannels)Create a TracingChannel with traceSync, tracePromise, and traceCallback.
ChannelThe channel class (subscribe, unsubscribe, publish, hasSubscribers).
The default/namespace import also exposes a boundedChannel helper (it is not a named ESM export). TracingChannel supports store binding via bindStore / runStores.

Behaviour notes

  • The channel registry holds strong references to channels.
  • Store-flow through bindStore is best-effort.

See also

  • Node.js upstream: