0
0
NestJSframework~10 mins

Event handling in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the EventEmitter2 class from NestJS.

NestJS
import { [1] } from '@nestjs/event-emitter';
Drag options to blanks, or click blank then click option'
AEventDispatcher
BEventHandler
CEventListener
DEventEmitter2
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names like EventHandler or EventListener.
Forgetting to import from '@nestjs/event-emitter'.
2fill in blank
medium

Complete the code to inject the EventEmitter2 into the service constructor.

NestJS
constructor(private readonly [1]: EventEmitter2) {}
Drag options to blanks, or click blank then click option'
AeventEmitter
BeventHandler
CeventListener
DeventDispatcher
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names that do not match the class.
Forgetting the private readonly keywords.
3fill in blank
hard

Fix the error in emitting an event with a payload.

NestJS
this.eventEmitter.[1]('user.created', { id: 1, name: 'Alice' });
Drag options to blanks, or click blank then click option'
AemitEvent
Bdispatch
Cemit
Dtrigger
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like emitEvent or dispatch.
Confusing with other event libraries.
4fill in blank
hard

Fill both blanks to create an event listener method that listens to 'order.placed' events.

NestJS
@[1]('order.placed')
handleOrderPlaced([2]: any) {
  console.log('Order received:', [2]);
}
Drag options to blanks, or click blank then click option'
AOnEvent
BEventHandler
Corder
Dpayload
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect decorator names like @EventHandler.
Using unclear parameter names.
5fill in blank
hard

Fill all three blanks to emit an event and handle it properly in NestJS.

NestJS
this.[1].[2]('payment.completed', { amount: 100 });

@[3]('payment.completed')
handlePaymentCompleted(payload: any) {
  console.log('Payment done:', payload.amount);
}
Drag options to blanks, or click blank then click option'
AeventEmitter
Bemit
COnEvent
Ddispatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method names like 'dispatch'.
Using wrong decorator names.