Event Management in Node.js

https://leanpub.com/node-and-express-simplified

Add the Events Module to Your Node.js Application

https://leanpub.com/node-and-express-simplified

Create and Trigger Events with the EventEmitter API

https://leanpub.com/node-and-express-simplified

Syntax

https://leanpub.com/node-and-express-simplified

Example 1: How to register a listener and trigger an event

https://leanpub.com/node-and-express-simplified

Example 2: How to pass arguments to an event listener

https://leanpub.com/node-and-express-simplified

Example 3: How to add multiple listeners to an event

https://leanpub.com/node-and-express-simplified

Important Emitter Methods for Managing Events in Node.js

https://leanpub.com/node-and-express-simplified

emitter.once() – running an event listener only once

https://leanpub.com/node-and-express-simplified

emitter.listeners() – checking all the listeners attached to an event

https://leanpub.com/node-and-express-simplified

emitter.listenerCount() – counting the listeners attached to an event

https://leanpub.com/node-and-express-simplified

emitter.eventNames() – getting the event names registered on an emitter object

https://leanpub.com/node-and-express-simplified

emitter.getMaxListeners() – checking the listener warning threshold

https://leanpub.com/node-and-express-simplified

emitter.prependListener() – adding a listener to the beginning of an event’s listeners array

https://leanpub.com/node-and-express-simplified

emitter.prependOnceListener() – adding a one-time listener to the beginning of an event’s listeners array

https://leanpub.com/node-and-express-simplified

emitter.removeListener() – removing a listener from an event’s listeners array

https://leanpub.com/node-and-express-simplified

Syntax

https://leanpub.com/node-and-express-simplified

Example: Remove a single listener

https://leanpub.com/node-and-express-simplified

Example: Remove multiple instances of the same listener

https://leanpub.com/node-and-express-simplified

Example: Removing a listener does not cancel its call in the current emission

https://leanpub.com/node-and-express-simplified

emitter.removeAllListeners() – removing all listeners

https://leanpub.com/node-and-express-simplified

Syntax

https://leanpub.com/node-and-express-simplified

Example 1: Remove a specific event’s listeners

https://leanpub.com/node-and-express-simplified

Example 2: Remove all listeners from a specific EventEmitter instance

https://leanpub.com/node-and-express-simplified

The node:events Module Provides APIs for Event Management

https://leanpub.com/node-and-express-simplified