Lightweight, framework-agnostic event handler library for both browser and Node.js environments
npm install simple-event-handlerA lightweight, framework-agnostic event handler library for both front-end and back-end JavaScript applications. Implement the pub/sub (publisher-subscriber) pattern to decouple your code and enable event-driven architecture. Works seamlessly in browsers, Node.js, and modern JavaScript frameworks like React, Vue, and Angular.
Perfect for managing application-wide events, component communication, real-time updates, and building loosely coupled, maintainable codebases.






- 🚀 Lightweight - Less than 2KB minified
- 🔧 Zero Dependencies - No external requirements
- 💪 TypeScript - Full type definitions included
- 🌐 Universal - Works in browser and Node.js
- ⚡ Fast - Optimized for performance
- 🔗 Method Chaining - Fluent API support
- 📦 Multiple Formats - UMD, CommonJS, ES Module
- ✅ 100% Test Coverage - Thoroughly tested
- Installation
- Quick Start
- Examples 📚
- API Documentation 📖
- Changelog 📝
- License
``bash`
npm install simple-event-handler
`bash`
yarn add simple-event-handler
`bash`
pnpm add simple-event-handler
`html`
`javascript
import eventHandler from 'simple-event-handler';
// Subscribe to an event
eventHandler.subscribe('user:login', (user) => {
console.log('User logged in:', user.name);
});
// Fire the event
eventHandler.fire('user:login', { name: 'John Doe' });
`
For comprehensive usage examples including React, Vue, TypeScript, and more, see EXAMPLES.md.
Quick examples:
`javascript
// Node.js / CommonJS
const eventHandler = require('simple-event-handler');
eventHandler.subscribe('event', (data) => console.log(data));
eventHandler.fire('event', { message: 'Hello!' });
// ES Modules / TypeScript
import eventHandler from 'simple-event-handler';
eventHandler.on('notification', (msg) => console.log(msg));
eventHandler.emit('notification', 'Hello from ESM!');
// Method chaining
eventHandler
.subscribe('update', (data) => console.log(data))
.fire('update', { value: 42 })
.unsubscribeAll('update');
`
For complete API reference, see API.md.
Quick Reference:
- subscribe(events, handler, $scope?) / on() - Register event handler(s)
- once(events, handler, $scope?) - Register one-time handler
- fire(name, args?) / emit() - Trigger event
- unsubscribe(name, handler) / off() - Remove specific handler
- unsubscribeAll(name) / offAll()` - Remove all handlers
MIT - See LICENSE file for details.