emitter.listeners()

Returns the array of listeners registered for an event, plus listenerCount.

Since Node 0.x Spec ↗

Syntax

emitter.listeners(eventName)  /  emitter.listenerCount(eventName)

Parameters

NameTypeRequiredDescription
eventName string | symbol Yes The event to inspect.

Returns

Function[] | number — listeners() returns a copy of the listener array; listenerCount() returns its length.

Examples

import { EventEmitter } from 'node:events';

const ee = new EventEmitter();
ee.on('go', () => {});
ee.on('go', () => {});
console.log(ee.listenerCount('go'));
Output
2
import { EventEmitter } from 'node:events';

const ee = new EventEmitter();
ee.once('boot', () => {});
console.log(ee.listeners('boot').length);
console.log(ee.eventNames());
Output
1
[ 'boot' ]

Notes

`listeners()` returns a snapshot copy, so mutating it does not affect the emitter. Useful for diagnostics and detecting listener leaks. `eventNames()` lists all events that currently have listeners.

See also