What is Event Emmitter?


EventEmitter class lies in events module. It is accessibly via following syntax:

//import events module
var events = require('events');
//create an eventEmitter object
var eventEmitter = new events.EventEmitter();

When an EventEmitter instance faces any error, it emits an 'error' event. When new listener is added, 'newListener' event is fired and when a listener is removed, 'removeListener' event is fired.

EventEmitter provides multiple properties like on and emiton property is used to bind a function with the event and emit is used to fire an event.


© 2017