Events
In-process event emitter for cross-cutting side effects. Decouples the service that owns the write from the services that care about it.
Purpose
When content is approved, three things happen:
- Thumbnail mips start generating.
- Tag usage counts tick up.
- Notifications (future) go out.
Putting all three inside ContentService.approve() bloats it and couples approval to unrelated domains. Emitting a single content.approved event and letting handlers subscribe keeps each concern in its own module.
Implementation
Mechanism
@nestjs/event-emitter (built-in, no broker required). Synchronous by default; mark handlers async for non-blocking work.
// src/events/events.module.ts
@Global()
@Module({
imports: [EventEmitterModule.forRoot({ wildcard: true, delimiter: '.' })],
exports: [EventEmitterModule],
})
export class EventsModule {}
Global scope so any module can emit without importing the events module.