0
0
NestJSframework~5 mins

WebSocket gateway creation in NestJS - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a WebSocket Gateway in NestJS?
A WebSocket Gateway in NestJS is a special class that handles WebSocket connections, allowing real-time communication between the server and clients.
Click to reveal answer
beginner
Which decorator is used to create a WebSocket Gateway in NestJS?
The @WebSocketGateway() decorator is used to mark a class as a WebSocket Gateway in NestJS.
Click to reveal answer
beginner
How do you listen for a specific WebSocket event in a NestJS Gateway?
Use the @SubscribeMessage('eventName') decorator on a method inside the Gateway class to listen for that event.
Click to reveal answer
intermediate
What method signature should a message handler have in a NestJS WebSocket Gateway?
A message handler method should accept two parameters: the client socket and the data sent by the client, e.g., handleMessage(client: Socket, payload: any).
Click to reveal answer
beginner
How can you send a message back to the client from a WebSocket Gateway in NestJS?
You can use the client.emit('eventName', data) method to send a message back to the connected client.
Click to reveal answer
Which decorator marks a class as a WebSocket Gateway in NestJS?
A@Controller()
B@WebSocketGateway()
C@Injectable()
D@Module()
How do you listen for a WebSocket event named 'chat' in a NestJS Gateway?
AUse @SubscribeMessage('chat') on a method
BUse @OnEvent('chat') on a method
CUse @Listen('chat') on a method
DUse @WebSocketEvent('chat') on a method
What parameters does a WebSocket message handler method usually receive?
Aonly client socket
Brequest and response objects
Conly payload data
Dclient socket and payload data
Which method sends a message back to the client in a NestJS WebSocket Gateway?
Agateway.emit()
Bclient.sendMessage()
Cclient.emit()
Dgateway.send()
What is the main purpose of a WebSocket Gateway in NestJS?
ATo handle real-time WebSocket communication
BTo serve static files
CTo manage database connections
DTo handle HTTP requests
Explain how to create a basic WebSocket Gateway in NestJS and listen for a message event.
Think about decorators and message handlers.
You got /5 concepts.
    Describe how a NestJS WebSocket Gateway handles incoming messages and sends responses.
    Focus on the flow of message handling.
    You got /5 concepts.