The @Res() decorator in NestJS injects the platform-specific response object (Express Response or Fastify Reply) into a controller method, enabling library-specific response handling.

Usage

import { Controller, Get, Res, HttpStatus } from '@nestjs/common';
import { Response } from 'express';
 
@Controller('cats')
export class CatsController {
  @Get()
  findAll(@Res() res: Response) {
    res.status(HttpStatus.OK).json([]);
  }
}

Trade-offs

Advantages:

  • Full control over response headers, status codes, and cookies
  • Access to library-specific features (e.g., Express res methods)

Disadvantages:

  • Code becomes platform-dependent (Express vs Fastify APIs differ)
  • Loses compatibility with NestJS features that rely on standard response handling (Interceptors, @HttpCode(), @Header() decorators)
  • More challenging testing (must mock response object)

See Passthrough Mode for a hybrid approach.