Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
What happens by default when an EventEmitter emits an 'error' event with no registered listener for it?
💻 Code Challenge | +75 XP
Build an OrderProcessor class extending EventEmitter that emits "started" and "completed" lifecycle events, includes a mandatory error listener setup, and uses .once() for a one-time "ready" initialization event.
A long-running service is showing steadily increasing memory usage, traced to an accumulating number of EventEmitter listeners on a shared event bus. Reorder the steps to fix it.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Emitting an 'error' event with no registered error listener
// Dangerous: crashes the whole process if this ever emits
const emitter = new EventEmitter();
emitter.emit("error", new Error("oops")); // uncaught, process crashes
// Correct: always handled
emitter.on("error", (err) => logger.error(err));
emitter.emit("error", new Error("oops")); // now safely logged insteadThe Solution //
This is the one EventEmitter behavior that differs dangerously from every other event — Node throws the unhandled error and crashes the entire process by default. Always register an explicit error listener on any emitter that might ever emit one, even if it just logs the error.
The Error //
Registering a new listener on a shared, long-lived EventEmitter on every request or connection, without ever removing it
// Wrong: a new listener on every connection, never removed
function handleConnection(socket) {
eventBus.on("update", () => sendUpdate(socket)); // accumulates forever
}
// Correct: cleaned up when the connection closes
function handleConnection(socket) {
const listener = () => sendUpdate(socket);
eventBus.on("update", listener);
socket.on("close", () => eventBus.off("update", listener));
}The Solution //
Each registered listener persists indefinitely (holding its entire captured closure in memory) until explicitly removed — in a long-running process, this accumulates listeners without bound, a classic memory leak pattern. Store a reference to the listener and remove it with .off() when the associated request or connection ends.