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

NameTypeDescription
eventNamestring | symbolName of the event.
listenerFunctionSpecific 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'));
Node.js Reference