Community Question Bundle

Express vs NestJS Middleware Quiz

Four questions comparing Express middleware to NestJS guards, interceptors, and pipes. Aimed at devs who came up on Express and keep reaching for `app.use()` when Nest already gives them a better seam.

Express vs NestJS Middleware Quiz

Four questions comparing Express middleware to NestJS guards, interceptors, and pipes. Aimed at devs who came up on Express and keep reaching for `app.use()` when Nest already gives them a better seam.

Question Bundle
TypeScript
4 questions
framework
api-design
interview-prep
isabellarashid

By @isabellarashid

December 30, 2025

·

Updated May 20, 2026

925 views

20

Rate

An Express middleware does auth and calls next() after attaching req.user. Port this to NestJS: should it be a Middleware, a Guard, or an Interceptor, and why?

Live example

Live example:

TypeScript
// Route protected by @UseGuards(AuthGuard):
// GET /me  (no Authorization header) -> 401 UnauthorizedException
// GET /me  (valid token)              -> handler runs, request.user = { id: 'u_1' }
// @Roles('admin') decorator on the handler is readable by the guard via Reflector,
// because Guards run AFTER route resolution (unlike Middleware).