Skip to content

Instantly share code, notes, and snippets.

@chaiwa-berian
Last active August 13, 2018 18:28
Show Gist options
  • Save chaiwa-berian/d31111486fec470050c7149a05cecf78 to your computer and use it in GitHub Desktop.
Save chaiwa-berian/d31111486fec470050c7149a05cecf78 to your computer and use it in GitHub Desktop.
Nodejs Events Demo
var events = require('events');
var emitter = new events.EventEmitter();
emitter.once('knock', function(){ //subscribe to the event
console.log('Who\'s there???');
});
emitter.on('knock', function(){ //subscribe to the event
console.log('Leave us in peace, please!!!');
});
emitter.emit('knock'); //fire the event
emitter.emit('knock'); //fire the event
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment