Last active
August 13, 2018 18:28
-
-
Save chaiwa-berian/d31111486fec470050c7149a05cecf78 to your computer and use it in GitHub Desktop.
Nodejs Events Demo
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
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