Questions
3 of 29
1What is a pipe in NestJS and what are its two primary uses?
2How does ValidationPipe work with class-validator and class-transformer in NestJS?
3What is the difference between applying a pipe at the param level vs handler level vs globally in NestJS?
4How do you write a custom pipe for parsing and validating a MongoDB ObjectId param in NestJS?
5What are all the built-in pipes NestJS ships with?
6What is class-transformer and how does it complement class-validator in NestJS?
7How do you write a custom pipe that sanitizes a string input (trim and lowercase) in NestJS?
8How do you write a pipe that uses metatype to skip validation for primitive types the same way ValidationPipe does?
9What are the two ways to register a global pipe in NestJS and what is the difference?
10What are all the significant ValidationPipe options and what does each do in NestJS?
11How do you unit test a custom pipe in NestJS?
12Can a pipe be asynchronous in NestJS and how do you implement one?
13How do you write an async custom validator that checks uniqueness against a database in NestJS?
14How do you validate arrays and conditional fields with class-validator in NestJS?
15How do you use validation groups with class-validator to apply different rules for create vs update operations in NestJS?
16What does @Exclude() and @Expose() do and how do you use them to strip sensitive fields from responses?
17What is the excludeExtraneousValues option in class-transformer and how does it differ from whitelist in ValidationPipe?
18How do you make a custom pipe configurable by accepting constructor options in NestJS?
19How do you customise the error response format produced by ValidationPipe in NestJS?
20How do you handle file upload validation with ParseFilePipe and custom file validators in NestJS?
21What interface must a custom pipe implement and what does the transform() method receive?
22What is the difference between a transformation pipe and a validation pipe in NestJS?
23How do you pass options to a built-in pipe like ParseIntPipe or ParseUUIDPipe in NestJS?
24What is class-validator and how does it integrate with NestJS ValidationPipe?
25What is the @ValidateNested() decorator and when must you pair it with @Type()?
26How do you write a custom class-validator decorator in NestJS?
27What does the @Transform() decorator do in class-transformer and when should you use it?
28How does @Type() interact with discriminated unions and polymorphic DTOs in class-transformer?
29How do you write a pipe that validates and parses a date string from a route parameter in NestJS?
03 / 29

What is the difference between applying a pipe at the param level vs handler level vs globally in NestJS?

Param-level applies the pipe to a single argument only. Handler-level (@UsePipes on the method) runs the pipe for all arguments of that handler. Controller-level applies to all handlers in the controller. Global applies to every request across the entire app. The global ValidationPipe is the standard for most apps.

Pipe binding at all four levels
Choosing the right binding level:
  1. 1

    Param-level — for transformation pipes like ParseIntPipe, ParseUUIDPipe on specific params.

  2. 2

    Handler-level — when only some routes need validation with specific options.

  3. 3

    Controller-level — when all routes in the controller share the same validation rules.

  4. 4

    Global — for ValidationPipe in most apps; register via APP_PIPE for DI support.

Difficulty: 6/10
Topics: Pipes, Scope, Validation

Scenario Questions

0-2 years experience
  1. 1

    If you need to validate a single DTO property in a controller method, how would you apply a pipe, and what would happen if you mistakenly applied it globally instead?

  2. 2

    Show me how you would add a built‑in ValidationPipe to just one route parameter. What does Nest do when the request reaches that handler?

  3. 3

    Suppose you have a simple GET endpoint that returns a number. How would you ensure the incoming query param is transformed to an integer using a pipe at the param level, and what error would the client see if the pipe is missing?

2-5 years experience
  1. 1

    We have a POST endpoint that creates a user and we want to validate the whole body. The team tried moving the ValidationPipe from the controller method to the module level, but validation stopped working for some fields. Walk me through why that happened and how you’d fix it.

  2. 2

    During a code review you notice a custom logging pipe applied at the handler level, but the same pipe is also registered globally. The logs are duplicated. How would you identify and resolve this conflict?

  3. 3

    Our microservice uses a global pipe to strip unknown properties, but a specific route needs to allow extra fields. How would you configure the pipe scopes to achieve this without breaking other routes?

5-8 years experience
  1. 1

    Imagine a high‑traffic API gateway that applies a global transformation pipe to every request. Some downstream services need raw payloads for performance. How would you redesign the pipe usage to balance global concerns with per‑handler exceptions?

  2. 2

    You’re refactoring a large monolith into feature modules. Several modules rely on a custom authentication pipe applied at the handler level, but you want to move it to a global scope to reduce boilerplate. What edge cases and performance implications would you evaluate before making that change?

  3. 3

    A bug appears only when a request passes through both a param‑level ParseIntPipe and a globally applied ValidationPipe that also tries to coerce types. Explain how pipe execution order could cause the issue and how you’d restructure the pipeline.

8+ years experience
  1. 1

    Our organization is standardizing on a global exception‑handling pipe, but some legacy services still use their own handler‑level pipes for validation. How would you plan a migration strategy that minimizes downtime and ensures consistent behavior across teams?

  2. 2

    Design a policy for pipe registration (global vs handler vs param) that scales across dozens of microservices, considering versioning, testing, and cross‑team ownership. What guidelines would you set and why?

  3. 3

    During a security audit you discover that a globally applied sanitization pipe is being bypassed on certain routes because developers added param‑level pipes that short‑circuit the pipeline. How would you enforce a contract to prevent such bypasses at the architecture level?

Follow-up Questions

  • Can you walk me through the exact order Nest executes multiple pipes at different scopes?
  • What are the performance or maintenance trade‑offs of moving a validation pipe from handler to global scope?
  • How does Nest propagate errors thrown inside a pipe when it’s applied globally versus at the param level?