Diagnostics
diagnostics_channel.hasSubscribers()
Checks whether a named channel currently has subscribers. Use it to skip expensive construction of optional telemetry, not as a guarantee of later delivery. Tested on Node.js 22.16.0. Example output (one line per entry): ["false", "true", "false"].
Formal Syntax & Structure
nodejs syntaxnodejs
diagnostics_channel.hasSubscribers(name)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | symbol | Channel name. |
Return Value
boolean
Whether subscribers exist.
Working Example
Example Snippetnodejs
import { hasSubscribers, subscribe, unsubscribe } from 'node:diagnostics_channel';const name = 'bytemind.v16.check';const handler = () => { };console.log(hasSubscribers(name));subscribe(name, handler);try { console.log(hasSubscribers(name));}finally { unsubscribe(name, handler);}console.log(hasSubscribers(name));