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
| Name | Type | Description |
|---|---|---|
| eventName | string | symbol | Name of the event. |
| listener | Function | Handler 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');