@Sse()

Maps a controller method to a Server-Sent Events stream endpoint.

Since NestJS 10/11 Spec ↗

Syntax

@Sse(path?: string)

Parameters

NameTypeRequiredDescription
path string No Optional route path appended to the controller prefix.

Returns

MethodDecorator — A decorator applied to the route handler method.

Examples

import { Controller, Sse } from '@nestjs/common';
import { interval, map, Observable } from 'rxjs';

@Controller('events')
export class EventsController {
  @Sse('stream')
  stream(): Observable<{ data: { now: number } }> {
    return interval(1000).pipe(
      map(() => ({ data: { now: Date.now() } })),
    );
  }
}

Notes

The handler must return an Observable emitting objects with a `data` property. Nest sets the text/event-stream content type and keeps the connection open, pushing each emission to the client.