Questions
23 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?
23 / 29

How do you pass options to a built-in pipe like ParseIntPipe or ParseUUIDPipe in NestJS?

Instantiate the pipe with an options object using new instead of passing the class reference. This lets you override the error HTTP status code, restrict UUID versions, or configure other pipe-specific behavior. When using new, the pipe is not resolved through DI — it cannot inject services.

Configuring built-in pipes with options
Class reference vs instance — key difference:
  1. 1

    Class reference (ParseIntPipe without new) — NestJS resolves it through the DI container.

  2. 2

    Instance (new ParseIntPipe({...})) — you control options but lose DI injection inside the pipe.

  3. 3

    Use class reference when the pipe has no options and may need injected services.

  4. 4

    Use instance when you need to pass specific options like errorHttpStatusCode or version.

  5. 5

    ParseFilePipe, ParseArrayPipe, ParseUUIDPipe, and ParseEnumPipe all accept option objects.

Difficulty: 5/10
Topics: Pipe options, Parameter validation, Global vs route-specific pipes

Scenario Questions

0-2 years experience
  1. 1

    You need to accept a query parameter 'page' as an integer in a NestJS controller. How would you use ParseIntPipe to ensure it's parsed, and how would you set a default value of 1 if the client omits it?

  2. 2

    A route expects a UUID path param 'id'. Show me how you'd apply ParseUUIDPipe with the version option set to '4'. What happens if the client sends an invalid UUID?

  3. 3

    If you want ParseIntPipe to reject negative numbers, which option would you use and how would you configure it in the route decorator?

2-5 years experience
  1. 1

    We have a GET endpoint that takes an optional 'limit' query param. The team wants to enforce that limit is between 1 and 100, default 20. How would you configure ParseIntPipe options to achieve this, and what would you do if the validation fails?

  2. 2

    During a code review you notice a controller uses ParseUUIDPipe without specifying the version, and a bug appears when a client sends a version‑5 UUID. How would you fix it, and what trade‑offs are there in enforcing a specific version globally?

  3. 3

    Our app uses a global ValidationPipe that also transforms numbers. A new requirement is to keep ParseIntPipe's custom error messages for certain routes. How would you pass custom error messages to ParseIntPipe while keeping the global pipe in place?

5-8 years experience
  1. 1

    Design a strategy for handling numeric and UUID parameters across dozens of microservices, ensuring consistent validation and error handling. How would you leverage pipe options, custom pipes, or global configuration, and what are the performance implications?

  2. 2

    We observed that using ParseIntPipe with the 'exceptionFactory' option adds overhead in high‑throughput endpoints. How would you evaluate the impact and decide whether to keep custom error factories or fallback to default behavior?

  3. 3

    A legacy service parses IDs manually and sometimes returns 500 on malformed input. You need to migrate it to use ParseUUIDPipe with strict version checking without breaking existing clients. Outline the migration steps and how you'd handle backward compatibility.

8+ years experience
  1. 1

    Our platform plans to standardize request validation across all teams, including numeric, UUID, and custom formats. As a staff engineer, how would you define a shared library of pipes with preset options, versioning, and deprecation policy, and what governance processes would you put in place?

  2. 2

    During a security audit it was discovered that some endpoints accept UUIDs without version constraints, potentially allowing injection attacks. How would you redesign the validation layer at the architectural level to enforce strict pipe options, and how would you roll this out across multiple services with minimal downtime?

  3. 3

    Consider a scenario where you need to support both v1 and v2 API contracts, each requiring different parsing rules for IDs (v1 uses numeric IDs, v2 uses UUID v4). How would you structure your NestJS modules and pipe configurations to handle this divergence while keeping the codebase maintainable?

Follow-up Questions

  • What changes if you omit the options object?
  • How does NestJS propagate validation errors from a pipe to the client?
  • When would you prefer a global pipe over per‑parameter configuration?