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
| Export | Description |
|---|---|
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. |
Channel | The channel class (subscribe, unsubscribe, publish, hasSubscribers). |
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
bindStoreis best-effort.
See also
- Node.js upstream: