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