Event emitter raises the event called
messageLogged
and passes the object as an argument
const EventEmitter = require('events');
const emitter = new EventEmitter();

// Register a listener
emitter.on('messageLogged', function(obj) {
  console.log('Listener called', obj);
});

// Raise an event & passes the object
emitter.emit('messageLogged', {key1: 'Value 1', key2: 'Value 2'});
by Valeri Tandilashvili
2 years ago
Node
Events
Node.js Tutorial for Beginners - 1 Hour
0
Pro tip: use ```triple backticks around text``` to write in code fences