Events
EventEmitter.listenerCount()
Reports how many handlers are registered for an event, optionally counting only one function. Tested on Node.js 22.16.0. Registering the same function twice creates two registrations; removing once does not remove both.
Formal Syntax & Structure
nodejs syntaxnodejs
emitter.listenerCount(eventName[, listener])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| eventName | string | symbol | Name of the event. |
| listener | Function | Specific handler to count. |
Return Value
number
Number of matching registrations.
Working Example
Example Snippetnodejs
import { EventEmitter } from 'node:events';const bus=new EventEmitter();const handler=()=>{};bus.on('ready',handler);bus.on('ready',handler);console.log(bus.listenerCount('ready',handler));bus.off('ready',handler);console.log(bus.listenerCount('ready'));