02 / 12

What is the APP_GUARD / APP_PIPE token pattern in NestJS?

Registering a global enhancer through the DI system using special tokens (APP_GUARD, APP_PIPE, APP_INTERCEPTOR, APP_FILTER) so the enhancer can inject services. This is the preferred approach over app.useGlobalGuards() for any enhancer that has dependencies like JwtService or Reflector.

Global guard with injected dependencies
Difficulty: 6/10
Topics: APP_GUARD, APP_PIPE, NestJS lifecycle

Scenario Questions

0-2 years experience
  1. 1

    How would you add a global authentication guard to all routes in a NestJS app using APP_GUARD?

  2. 2

    What happens if you register a validation pipe using APP_PIPE but forget to import ValidationPipe from '@nestjs/common'?

2-5 years experience
  1. 1

    A user reports that POST requests are failing with 400 errors, but the validation pipe logs show no output — how would you debug whether APP_PIPE is even being applied?

  2. 2

    You added a global guard to restrict access to admin routes, but now some public endpoints are blocked — what’s likely wrong, and how would you fix it?

5-8 years experience
  1. 1

    You’re migrating a legacy NestJS app to use modular guards instead of global ones — what edge cases might break when replacing APP_GUARD with module-scoped guards, and how would you test for them?

  2. 2

    How would you design a system where different microservices use different APP_PIPE implementations for request validation, while avoiding duplication and ensuring consistent error responses?

8+ years experience
  1. 1

    You’re leading a cross-team migration from global APP_GUARD/APP_PIPE to per-module implementations across 12 services — what architectural tradeoffs do you consider for maintainability, rollout risk, and observability?

  2. 2

    How would you design a long-term strategy to phase out legacy APP_PIPE logic that’s tightly coupled to deprecated DTOs, while ensuring zero downtime and backward compatibility for external clients?

Follow-up Questions

  • What happens if you register a global pipe that throws an error on invalid input?
  • How would you debug a guard that’s not being triggered on a specific route?
  • Can you use APP_GUARD and APP_PIPE in a feature module, or only globally?