events & EventEmitter: Patterns and Pitfalls
On this page
Event-Driven Foundations
The EventEmitter class underpins Node's architecture. Streams, HTTP servers, and sockets are built on top of it.
import { EventEmitter } from 'events';
const emitter = new EventEmitter();
emitter.on('ready', () => console.log('System ready'));
emitter.emit('ready');
Production Patterns
Events enable loose coupling between modules. Avoid global emitters and uncontrolled listener growth which can cause memory leaks.
Operational Insight
Monitor listener counts in long-running services to prevent leaks and unexpected behavior.