Diagnostics
channel.publish()
Delivers a message synchronously to current subscribers. It does not create a durable queue or remote trace exporter. Keep the payload small and non-secret; subscriber code must not throw. Tested on Node.js 22.16.0. Example output (one line per entry): ["3"].
Formal Syntax & Structure
nodejs syntaxnodejs
channel.publish(message)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| message | any | Diagnostic payload. |
Return Value
undefined
No return value.
Working Example
Example Snippetnodejs
import { channel, subscribe, unsubscribe } from 'node:diagnostics_channel';const name = 'bytemind.v16.publish';const c = channel(name);const handler = data => console.log(data.count);subscribe(name, handler);try { c.publish({ count: 3 });}finally { unsubscribe(name, handler);}