emitter.removeListener()

Removes a specific listener, or removeAllListeners removes every listener for an event.

Since Node 0.x Spec ↗

Syntax

emitter.removeListener(name, listener)  /  emitter.removeAllListeners([name])

Parameters

NameTypeRequiredDescription
eventName string | symbol Yes The event name.
listener function Yes The listener reference to remove.

Returns

EventEmitter — The emitter, for chaining.

Examples

import { EventEmitter } from 'node:events';

const ee = new EventEmitter();
function h() {}
ee.on('x', h);
ee.removeListener('x', h);
console.log(ee.listenerCount('x'));
Output
0
import { EventEmitter } from 'node:events';

const ee = new EventEmitter();
ee.on('a', () => {});
ee.on('a', () => {});
ee.removeAllListeners('a');
console.log(ee.listenerCount('a'));
Output
0

Notes

`removeListener` is the original name; `off` is the modern alias and behaves identically. `removeAllListeners()` with no argument clears every event; avoid calling it on shared emitters like `process`.

See also