Day 83 Node.js Event Emitters

What are event emitters?

Node.js core API is based on the asynchronous event-driven architecture in which certain kind of objects called emitters periodically emits events that cause listener objects to be called.

All objects that emit events are exposed on eventEmitter.on() function that allows one or more functions to be attached to named events emitted by the object.

Event emitters allow us to not have a lot of if this happens then run this function and if this happens run this function repeating over and over again. Instead, we can just listen for an event.

Creating an emitter is essentially just an object full arrays and functions. But it is a very clean and a way to control the flow of events that happen in your code.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Up ↑

%d bloggers like this: