
Event-Driven Architecture with @hazeljs/event-emitter
Decouple your application with decorator-based events—NestJS-style, HazelJS-native. Event-driven architecture is one of the most effective ways to keep your codebase flexible and maintainable. When an order is created, you might need to send a confirmation email, update analytics, notify inventory, and log the action. Wiring all of that with direct method calls creates a tangled web of dependencies. The @hazeljs/event-emitter package solves this by letting you emit events and listen for them with a clean, decorator-based API—similar to what NestJS developers know and love. Why Event-Driven? In a typical request handler, you might do something like: // ❌ Tightly coupled - every new side effect requires editing this method async createOrder ( dto : CreateOrderDto ) { const order = await this . orderRepo . save ( dto ); await this . emailService . sendConfirmation ( order ); await this . analyticsService . track ( ' order_created ' , order ); await this . inventoryService . reserve ( orde
Continue reading on Dev.to JavaScript
Opens in a new tab



