Cheat Sheet

Node.js Event Emitter Cheat Sheet

By Alex Alykiotis
June 22, 2021

Node.js event emitters cheat sheet cover

Event Emitters are one of the most important built-in APIs since much of Node.js' core is built around an idiomatic asynchronous event-driven architecture. Event Emitters can help developers create a publisher-subscriber pattern with ease. After reading this cheat sheet, the readers will have a better understanding of how to:

  • Create an event-emitter instance
  • Emitting events
  • Listening for events
  • Handling multiple events
  • Configuring event emitters

Cheat Sheet Excerpt

EventEmitter.prototype.setMaxListeners()

Sets the maximum allowed listeners for a specific event. Node.js will print a warning if more than 10 listeners are added for a specific event. setMaxListeners allows you to modify this limit.

myEmitter.setMaxListeners(25);

Want to see more? Get the full cheat sheet.

Tags: nodejs javascript

Comments