Diagnostics
diagnostics_channel.subscribe()
Registers a callback for messages on the named channel. The callback receives the payload and channel name. Retain the same function identity for later unsubscription; avoid logging credentials or customer data. Tested on Node.js 22.16.0. Example output (one line per entry): ["true demo"].
Formal Syntax & Structure
nodejs syntaxnodejs
diagnostics_channel.subscribe(name, onMessage)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | symbol | Channel name. |
| onMessage | Function | Message handler. |
Return Value
undefined
Registers subscriber.
Working Example
Example Snippetnodejs
import { channel, subscribe, unsubscribe } from 'node:diagnostics_channel';const name = 'bytemind.v16.sub';const handler = (data, channelName) => console.log(channelName === name, data.id);subscribe(name, handler);try { channel(name).publish({ id: 'demo' });}finally { unsubscribe(name, handler);}