Events

EventEmitter.prependListener()

Places a listener at the front of the current event listener list. Tested on Node.js 22.16.0. Listener ordering is synchronous for ordinary emission; this does not wait for promises returned by listeners.

Formal Syntax & Structure

nodejs syntaxnodejs
emitter.prependListener(eventName, listener)

Parameters & Attributes

NameTypeDescription
eventNamestring | symbolName of the event.
listenerFunctionHandler function.

Return Value

EventEmitter

The same emitter.

Working Example

Example Snippetnodejs
import { EventEmitter } from 'node:events';const bus=new EventEmitter();bus.on('ready',()=>console.log('second'));bus.prependListener('ready',()=>console.log('first'));bus.emit('ready');
Node.js Reference