Skip to content

Instantly share code, notes, and snippets.

@joepie91
Created July 4, 2015 08:13
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 joepie91/82df4eff6956089e3fbf to your computer and use it in GitHub Desktop.
Save joepie91/82df4eff6956089e3fbf to your computer and use it in GitHub Desktop.
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