emitter.removeListener()
Removes a specific listener, or removeAllListeners removes every listener for an event.
Syntax
emitter.removeListener(name, listener) / emitter.removeAllListeners([name]) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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`.