Node.js - Event Emitter

https://nodejs.org/api/events.html

https://www.youtube.com/watch?v=W8JeWFcceuA&index=6&list=PLdtEimKxDSoXDq-zE2YZuJtbERh4x0lxm

  • Support Node.JS to maintain concurrency
  • Objects That generate events are called event emitters
  • Events module must be imported for creating Event Emitters
  • Event Emitter instance can create new event through emit()
var events = require('events');
// Create an eventEmitter objectvar emitter = new events.EventEmitter();

emitter.on('addUser', function (user, pass) {
   console.log('Added user '+user);
});

var uid = 'imanali';
var pwd = 'tutorialpass';
//add the user emit an eventemitter.emit('addUser', uid, pwd);