emitter.off()

Removes a previously registered listener for an event (alias of removeListener).

Since Node 10 Spec ↗

Syntax

emitter.off(eventName, listener)

Parameters

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

Returns

EventEmitter — The emitter, for chaining.

Examples

import { EventEmitter } from 'node:events';

const ee = new EventEmitter();
const handler = () => console.log('tick');
ee.on('t', handler);
ee.emit('t');
ee.off('t', handler);
ee.emit('t');
Output
tick
const ac = new AbortController();
emitter.on('data', onData, { signal: ac.signal });
ac.abort(); // removes the listener

Notes

You must pass the same function reference used in `on`; anonymous or bound functions cannot be removed unless you keep a reference. Passing an AbortSignal via options is a cleaner removal pattern.

See also