🦅 NestJS
Beginner
What is the difference between @Res() and res in NestJS?
Answer
NestJS has two modes for working with HTTP responses. The standard mode (recommended) returns a value from a controller method — NestJS serializes and sends it automatically. Library-specific mode uses @Res() to inject the underlying Express/Fastify response object, giving full control but bypassing NestJS features like interceptors and serialization. Mixing them requires @Res({ passthrough: true }) which allows you to use the response object (e.g., to set cookies or headers) while still using NestJS response handling. The standard approach is preferred because interceptors, exception filters, and serializers work correctly. Use @Res() only when you need low-level response control like streaming or specific header manipulation.