midNode.js
Mid: Master the EventEmitter Pattern (Topic 12)
Updated May 4, 2026
Short answer
EventEmitter is a class that facilitates communication between objects in Node.js.
Deep explanation
Many core Node.js modules (like HTTP, Streams) inherit from EventEmitter. It works on the Observer pattern: an object (emitter) emits named events that cause functions (listeners) to be called. It is essential for building decoupled and scalable asynchronous architectures.
Real-world example
Creating a logging system where different modules emit 'log' events to a central listener.
Common mistakes
- Adding too many listeners to a single emitter, leading to memory leaks and warnings.
Follow-up questions
- What is the default limit of listeners?