@Res()
Injects the underlying platform response object into a handler parameter.
Syntax
@Res({ passthrough?: boolean }) | @Response() Parameters
| Name | Type | Required | Description |
|---|---|---|---|
passthrough | boolean | No | When true, Nest still handles the response while exposing the native object. |
Returns
ParameterDecorator — A decorator that binds the native response object.
Examples
import { Controller, Get, Res } from '@nestjs/common';
import { Response } from 'express';
@Controller('files')
export class FilesController {
@Get('download')
download(@Res() res: Response) {
res.set('Content-Type', 'text/plain').send('data');
}
@Get('cookie')
setCookie(@Res({ passthrough: true }) res: Response) {
res.cookie('token', 'abc');
return { ok: true };
}
}
Notes
Using @Res() without passthrough disables Nest's standard response handling
so you must end the response yourself. Pass `{ passthrough: true }` to set
headers or cookies while still returning a value normally.