Complete the code to import the EventEmitter2 class from NestJS.
import { [1] } from '@nestjs/event-emitter';
The EventEmitter2 class is imported from @nestjs/event-emitter to handle events in NestJS.
Complete the code to inject the EventEmitter2 into the service constructor.
constructor(private readonly [1]: EventEmitter2) {}private readonly keywords.The injected property should be named eventEmitter to clearly represent the EventEmitter2 instance.
Fix the error in emitting an event with a payload.
this.eventEmitter.[1]('user.created', { id: 1, name: 'Alice' });
The correct method to emit an event in NestJS EventEmitter2 is emit.
Fill both blanks to create an event listener method that listens to 'order.placed' events.
@[1]('order.placed') handleOrderPlaced([2]: any) { console.log('Order received:', [2]); }
The @OnEvent decorator listens to events, and the method parameter is commonly named payload to hold event data.
Fill all three blanks to emit an event and handle it properly in NestJS.
this.[1].[2]('payment.completed', { amount: 100 }); @[3]('payment.completed') handlePaymentCompleted(payload: any) { console.log('Payment done:', payload.amount); }
Use eventEmitter.emit to send events and @OnEvent decorator to listen to them.