Execution Order & Scopes

Preview — 3 of 10 questions

Place these in the correct order for a single successful request: Pipes, Guards, Interceptors (pre), Route Handler, Interceptors (post), Middleware.

javascript
// Single request happy path:
// Middleware -> Guards -> Interceptor(pre) -> Pipes -> Handler -> Interceptor(post)
//   (Exception Filters catch throws anywhere after middleware)
AMiddleware → Guards → Interceptors (pre) → Pipes → Handler → Interceptors (post)
BGuards → Middleware → Pipes → Interceptors (pre) → Handler → Interceptors (post)
CMiddleware → Pipes → Guards → Handler → Interceptors (pre) → Interceptors (post)
DInterceptors (pre) → Middleware → Guards → Pipes → Handler → Interceptors (post)

Guards are registered globally, on the controller, and on the method. In what order are they evaluated for a request?

javascript
// Evaluation order: APP_GUARD (global) -> @UseGuards on controller -> @UseGuards on method
// All must return true for the handler to run.
AMethod → Controller → Global
BGlobal → Controller → Method
CThey run in registration order regardless of scope
DOnly the most specific (method) guard runs

Two guards are listed in one @UseGuards(A, B). What logic combines them?

javascript
import { Controller, Get, UseGuards } from '@nestjs/common';
import { AuthGuard } from './auth.guard';
import { RolesGuard } from './roles.guard';

@Controller('admin')
@UseGuards(AuthGuard, RolesGuard) // AuthGuard AND RolesGuard must pass
export class AdminController {
  @Get() index() { return 'ok'; }
}
AOR — the request passes if either A or B returns true
BAND — both A and B must return true (and they short-circuit on the first false)
CXOR — exactly one must return true
DThey run independently and the last one wins

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.