NestJS · Middle · Question 39 of 75

What is a WebSocket gateway in Nest?

@WebSocketGateway()
export class ChatGateway {
  @SubscribeMessage("message")
  handle(@MessageBody() text: string) {}
}

Explanation

Guards, pipes, interceptors and filters work in gateways too. With several instances, use a Redis adapter to broadcast.

Further reading

Problem with a question

NestJS · Middle · question 39

Test yourself

Take the NestJS · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz