Bird
0
0

How do you correctly apply a pipe globally in a NestJS application?

easy📝 Syntax Q3 of 15
NestJS - Pipes
How do you correctly apply a pipe globally in a NestJS application?
Aapp.useGlobalPipes(new ValidationPipe());
Bapp.usePipes(ValidationPipe);
C@UsePipes(ValidationPipe) on the main app module
DBind the pipe inside each controller constructor
Step-by-Step Solution
Solution:
  1. Step 1: Understand global pipe binding

    Global pipes are applied to all incoming requests and are bound using the useGlobalPipes() method on the NestJS application instance.
  2. Step 2: Identify correct syntax

    The correct syntax requires creating an instance of the pipe, e.g., new ValidationPipe(), and passing it to app.useGlobalPipes().
  3. Final Answer:

    app.useGlobalPipes(new ValidationPipe()); -> Option A
  4. Quick Check:

    Check for new keyword and method name useGlobalPipes [OK]
Quick Trick: Global pipes use app.useGlobalPipes(new Pipe()) [OK]
Common Mistakes:
  • Forgetting to instantiate the pipe with 'new'
  • Using app.usePipes instead of app.useGlobalPipes
  • Trying to bind globally via decorators
  • Binding pipes inside controller constructors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes