Event Driven Apps - adriana-401-advanced-javascript/seattle-javascript-401n13 GitHub Wiki

An example of an event emitter:

const EventEmitter = require('events').EventEmitter;
const chatRoomEvents = new EventEmitter;

function userJoined(username){
  // Assuming we already have a function to alert all users.
  alertAllUsers('User ' + username + ' has joined the chat.');
}

// Run the userJoined function when a 'userJoined' event is triggered.
chatRoomEvents.on('userJoined', userJoined);

So what's going on here is we have a chat room, the event that we are listening for is a user joining, once a user joins, the function userJoinged should emit a message alerting the subscribers of the user joining.

This very much depends on the broadcasting and subscriber. One sends out the information, the subscribers hear the information if all goes well.

https://medium.com/technoetics/node-js-event-emitter-explained-d4f7fd141a1a https://alligator.io/nodejs/event-driven-programming/