0
0
NestJSframework~5 mins

Event handling in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is event handling in NestJS?
Event handling in NestJS is a way to listen for and respond to events within the application, allowing different parts of the app to communicate without tight coupling.
Click to reveal answer
beginner
Which decorator is used to listen to events in NestJS?
The @OnEvent() decorator is used to mark a method as an event listener for a specific event name.
Click to reveal answer
beginner
How do you emit an event in NestJS?
You use the EventEmitter2 service's emit() method, passing the event name and optional payload to notify listeners.
Click to reveal answer
intermediate
Why use event handling in NestJS instead of direct method calls?
Event handling decouples components, making the app easier to maintain and extend by allowing parts to react to events without knowing who triggered them.
Click to reveal answer
beginner
What must you do to enable event handling in a NestJS application?
You must import and provide the EventEmitterModule in your module to use event handling features.
Click to reveal answer
Which NestJS module provides event handling capabilities?
ACacheModule
BHttpModule
CConfigModule
DEventEmitterModule
What decorator do you use to listen for an event named 'user.created'?
A@Listen('user.created')
B@EventListener('user.created')
C@OnEvent('user.created')
D@Subscribe('user.created')
How do you send data with an event in NestJS?
APass data as the second argument to emit()
BUse a global variable
CAttach data to the event name string
DNestJS events cannot carry data
What is a benefit of using event handling in NestJS?
ADecouples components for better maintainability
BSimplifies direct method calls
CTight coupling between components
DRemoves the need for modules
Which service do you inject to emit events in NestJS?
AHttpService
BEventEmitter2
CConfigService
DLoggerService
Explain how to set up and use event handling in a NestJS application.
Think about module setup, sending, and receiving events.
You got /4 concepts.
    Describe the advantages of using event handling in NestJS compared to direct method calls.
    Consider how event handling affects app structure and flexibility.
    You got /4 concepts.