1. Home
  2. Node
  3. Eventemitter

EventEmitter is a Node native class containing a set of methods to operate on the events.

#node#module#events
const EventEmitter = require('events');
const emitter = new EventEmitter();

// Set an event listener
emitter.on('userSubscribed', function(eventArg){
    console.log("User subscribed at ", eventArg.date);
    // Do something when user subscribes
});

// Raise an event and pass data as the second argument
emitter.emit('userSubscribed', {date: Date.now()})
copy
Full Node cheatsheet
NordVPN NordVPN