The Observer Pattern: The EventEmitter Class
Learn about what the EventEmitter class is and how to create and use it.
We'll cover the following...
Another important and fundamental pattern used in Node.js is the Observer pattern. Together with the Reactor pattern and callbacks, the Observer pattern is an absolute requirement for mastering the asynchronous world of Node.js.
The Observer pattern is the ideal solution for modeling the reactive nature of Node.js and a perfect complement for callbacks.
The Observer pattern defines an object (called subject) that can notify a set of observers (or listeners) when a change in its state occurs.
The main difference from the Callback pattern is that the subject can actually notify multiple observers, while a traditional CPS callback will usually propagate its result to only one listener, the callback. ...