Created
February 21, 2016 05:16
-
-
Save dineshsprabu/67d3e42f53b7df996fd8 to your computer and use it in GitHub Desktop.
[NodeJS] Simple example of Events in NodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* npm install events */ | |
var EventEmitter = require('events').EventEmitter; | |
/* creating an event emitter object */ | |
var eventObj = new EventEmitter(); | |
/* making it to listen for the event (catchme) with resulting action (console.log) */ | |
eventObj.on('catchme', function(){ | |
console.log(" You Catched Me! "); | |
}); | |
/* emitting the event (catch me) */ | |
eventObj.emit('catchme'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment