Skip to content

Instantly share code, notes, and snippets.

@ugultopu
Created October 18, 2020 18:14
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 ugultopu/2f3b861276cd9335f44e61f79724d967 to your computer and use it in GitHub Desktop.
Save ugultopu/2f3b861276cd9335f44e61f79724d967 to your computer and use it in GitHub Desktop.
An example that demonstrates how to create a custom event in NodeJS
// Credits: https://youtu.be/ENrzD9HAZK4?t=403
const { EventEmitter } = require('events');
const eventEmitter = new EventEmitter();
eventEmitter.on('lunch', () => {
console.log('yum 🍣');
});
eventEmitter.emit('lunch');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment