Events

EventEmitter.on()

Registers a recurring listener for a named event. Repeated registrations are not deduplicated.

Formal Syntax & Structure

nodejs syntaxnodejs
emitter.on(eventName, listener)

Parameters & Attributes

NameTypeDescription
eventNamestring | symbolName of event.
listenerFunctionFunction called on emission.

Return Value

EventEmitter

The emitter for chaining.

Working Example

Example Snippetnodejs
import { EventEmitter } from 'node:events';const e=new EventEmitter(); e.on('ready', console.log); e.emit('ready', 4);
Node.js Reference