Skip to content

Instantly share code, notes, and snippets.

@dineshsprabu
Created February 21, 2016 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dineshsprabu/67d3e42f53b7df996fd8 to your computer and use it in GitHub Desktop.
Save dineshsprabu/67d3e42f53b7df996fd8 to your computer and use it in GitHub Desktop.
[NodeJS] Simple example of Events in NodeJS
/* 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