Skip to content

Instantly share code, notes, and snippets.

@TheEpicFace007
Created August 22, 2020 22:12
Show Gist options
  • Save TheEpicFace007/53a85b680a792ae84a1e892379e5ba2f to your computer and use it in GitHub Desktop.
Save TheEpicFace007/53a85b680a792ae84a1e892379e5ba2f to your computer and use it in GitHub Desktop.
node js event using the node event sdlib
const events = require('events');
let eventEmitter = new events.EventEmitter();
//Create an event handler:
let myEventHandler = function () {
console.log('I hear a scream!');
}
//Assign the event handler to an event:
eventEmitter.on('scream', myEventHandler);
//Fire the 'scream' event:
eventEmitter.emit('scream');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment