An open API service indexing awesome lists of open source software.

https://github.com/rupachowrasia/nodejs-event-emitter-for-pub-sub

A sample app to demostrate how node.js event emitters work
https://github.com/rupachowrasia/nodejs-event-emitter-for-pub-sub

emitter eventsemitter node-eventemitter node-events nodejs pubsub ticketing-system

Last synced: about 2 months ago
JSON representation

A sample app to demostrate how node.js event emitters work

Awesome Lists containing this project

README

          

# Node.js Event Emitters
> In Node.js, the events module provides a way to implement event-driven architecture, where different parts of your application can communicate via emitting and listening to events.

## 🧡 When to Use

- Logging
- Messaging/event systems
- Async task management (e.g., background workers)
- Microservices event communication
- Streaming APIs
- Real-world use case - chat app, ticket system and logger

## πŸ“š Key Methods
- emitter.on(): Adds an event listener
- emitter.emit(): Triggers an event
- emitter.once(): Listens only for the first occurrence
- emitter.removeListener() / off(): Removes a listener
- emitter.removeAllListeners(): Clears all listeners for a given event

## 🚨 Tips
- Don’t forget to remove unused listeners to avoid memory leaks.
- You can increase the listener limit (default is 10):

## πŸ›  Tech Stack

- Node.js
- Node.js events module

## πŸ“¦ Installation

```bash
# Clone the repo
git clone https://github.com/rupachowrasia/nodejs-event-emitter-for-pub-sub.git

# Move into the project directory
cd nodejs-event-emitter-for-pub-sub

# Install dependencies
npm install

# Run the app
npm run start