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

Can a pipe be asynchronous in NestJS and how do you implement one?

Yes. The transform() method can return a Promise and NestJS automatically awaits it before injecting the value into the handler. Async pipes are used for database-backed validation — for example, checking that an entity exists and returning it directly so the handler receives the full object instead of a raw ID string.

Async pipe that resolves a User from the database
Async pipe rules and considerations:
  1. 1

    Return Promise<T> from transform() — NestJS awaits it before calling the handler.

  2. 2

    Async pipes that inject services must use the DI container — register as @Injectable() provider.

  3. 3

    Pass the pipe as a class reference so NestJS resolves its dependencies: @Param('id', UserExistsPipe).

  4. 4

    Using new UserExistsPipe() bypasses DI — the injected service will be undefined.

  5. 5

    Async pipes increase request latency by the time of the awaited operation — use wisely.

Difficulty: 5/10
Topics: asynchronous pipes, validation, dependency injection

Scenario Questions

0-2 years experience
  1. 1

    You need to validate a request body against a database lookup before the controller runs. How would you create an async pipe to perform that check in NestJS?

  2. 2

    If you forget to mark the pipe's transform method as async, what runtime behavior would you see when the pipe returns a Promise?

  3. 3

    Where would you register this async pipe if you only want it applied to a single endpoint?

2-5 years experience
  1. 1

    During a sprint you added an async validation pipe that calls an external service, but the endpoint now sometimes hangs. What could be causing the hang and how would you debug it?

  2. 2

    You notice that errors thrown inside your async pipe are being returned as 500 instead of 400. What might be wrong with your implementation?

  3. 3

    Explain the trade‑offs between using a global async pipe versus attaching it per‑controller in a large codebase.

5-8 years experience
  1. 1

    Design a strategy for introducing a reusable async pipe that performs rate‑limit checks across multiple microservices, considering performance and error handling.

  2. 2

    How would you modify an existing synchronous validation pipe to become async without breaking existing unit tests and ensuring backward compatibility?

  3. 3

    Discuss the impact on request latency and thread pool usage when many async pipes are chained in a high‑traffic NestJS gateway.

8+ years experience
  1. 1

    Your organization plans to migrate legacy validation logic spread across services into a centralized async pipe library. What architectural considerations, versioning strategy, and cross‑team coordination would you propose?

  2. 2

    When scaling to millions of requests per second, how would you evaluate whether async pipes are a bottleneck and what alternatives could you employ at the framework level?

  3. 3

    How would you ensure observability and tracing for async pipe execution across distributed services while keeping the API contract stable?

Follow-up Questions

  • What happens if you forget to await an async call inside the pipe?
  • How does Nest handle errors thrown from an async pipe compared to a sync one?
  • When would you choose a global async pipe over a route‑specific one?