Skip to content

Instantly share code, notes, and snippets.

@joepie91 joepie91/.js

Created Jul 4, 2015
Embed
What would you like to do?
Node.js EventEmitter example
var EventEmitter = require("events").EventEmitter;
var door = new EventEmitter();
door.on("doorbell", function(seconds){
console.log("Doorbell rang for " + seconds + " seconds.");
person.openDoor();
});
/* In another file, for example... */
function ring(seconds) {
door.emit("doorbell", seconds);
}
ring(3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.