LearnThatStack Ace your next interview
Backend Development

Nest.js.

Start free Change topic Change
Practice · Questions

All questions

Showing of 50
Beginner 13
01

Explain the core building blocks of a Nest.js application.

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

A Nest.js application is built from modules, controllers and providers. A module is a class decorated with @Module() that groups related controllers and providers and encapsulates them. A controller handles incoming requests and returns responses. A provider is a class Nest can inject, such as a service, a repository or a factory. Services hold the business logic and are the most common providers.

Smaller pieces bound to a route run around its handler:

  • Middleware runs before the route handler.
  • Guards decide whether a request should be handled.
  • Interceptors add logic around the handler and can transform its result.
  • Pipes transform and validate input data.
  • Exception filters handle errors and turn them into responses.
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What are decorators in Nest.js, and what are some examples?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Decorators are functions you attach with the @ sign to a class or to its methods, properties and parameters. Each one adds metadata to its target. Nest reads that metadata to build routes and to wire up dependency injection.

Nest uses three main kinds:

  • Class decorators say what a class is. @Module() defines a module, @Controller() defines a controller, and @Injectable() makes a class injectable as a provider.
  • Method decorators such as @Get() and @Post() map a method to an HTTP route.
  • Parameter decorators read the request. @Param() reads a route parameter, @Query() the query string, and @Body() the request body.
@Injectable()        // Makes class injectable
export class UsersService {}

@Controller('users')  // Defines a controller
export class UsersController {
  @Get(':id')          // HTTP GET method
  findOne(@Param('id') id: string, @Query() query: Record<string, string>) {} // Route parameter, query parameters

  @Post()              // HTTP POST method
  create(@Body() body: CreateUserDto) {} // Request body
}

@Module({ controllers: [UsersController], providers: [UsersService] }) // Defines a module
export class UsersModule {}

Nest relies on TypeScript's experimentalDecorators and emitDecoratorMetadata options, which nest new turns on in tsconfig.json.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

What is the difference between @Injectable() and @Controller()?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

@Injectable() marks a class as a provider that Nest can create and inject into other classes. @Controller() marks a class as a controller that handles HTTP requests, optionally under a route prefix such as 'users'.

Use @Injectable() for services, repositories and other classes that hold business logic. You list them in a module's providers array. Nest then injects them into the constructors of controllers and other providers in that module.

Use @Controller() for the classes that define your API endpoints. Their methods carry route decorators such as @Get() and @Post(), and you list the class in a module's controllers array.

Controllers can have services injected into them, but services are not controllers. Keep controllers thin. They read the request and hand the business logic and data access to services.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

Explain modules in Nest.js and their purpose.

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

A module is a class decorated with @Module() that groups a related set of controllers and providers. Every application has at least one, the root module, and Nest builds its dependency graph starting from it.

@Module({
  imports: [DatabaseModule],      // Other modules to import
  controllers: [UserController],  // Controllers in this module
  providers: [UserService],       // Services/providers in this module
  exports: [UserService]          // Providers to export for other modules
})
export class UserModule {}

By default, a module encapsulates its providers. Another module can inject only the providers listed in exports, and only after it adds this module to its imports.

Modules give you:

  • a small public API for each feature, through exports
  • a clear separation of concerns, one module per feature
  • reuse of the same module across applications
  • lazy loading through LazyModuleLoader, which loads a module only when it is needed
Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

What is middleware in Nest.js and how do you implement it?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

Middleware is a function or class that runs before the route handler. It gets the request and response objects and a next() function. It can read or change the request and the response, end the response early, or call next() to pass control on. If it neither ends the response nor calls next(), the request is left hanging.

@Injectable()
export class LoggerMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    console.log(`${req.method} ${req.url}`);
    next();
  }
}

// Apply in module
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(LoggerMiddleware)
      .forRoutes('users');
  }
}

A class middleware implements NestMiddleware and its use() function. To apply it, the module implements NestModule and registers it in configure() through the MiddlewareConsumer. forRoutes() takes a path, a controller class, or a route object with a path and an HTTP method. exclude() skips routes.

Nest middleware works like Express middleware by default, so most Express middleware packages work in Nest too.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

What are DTOs and why are they important?

Beginner ·

Answer it yourself first - out loud, or typed below.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

A Data Transfer Object (DTO) is a class that defines the shape of data sent over the network, such as a request body. Nest recommends classes over TypeScript interfaces. Interfaces are removed at compile time, and pipes need a real class at runtime.

export class CreateUserDto {
  @IsString()
  @IsNotEmpty()
  name: string;
  @IsEmail()
  email: string;
  @IsInt()
  @Min(18)
  age: number;
}

@Post()
createUser(@Body() createUserDto: CreateUserDto) {
  return this.userService.create(createUserDto);
}

The class-validator decorators only describe the rules. They run when ValidationPipe is active, usually registered once with app.useGlobalPipes(new ValidationPipe()). An invalid body then gets a 400 Bad Request response before the handler runs.

DTOs give you type safety in the handler, input validation and a clear data contract. @nestjs/swagger also reads DTO classes to generate API documentation.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

How do you connect to a database in Nest.js?

Part of Pro
08

What is the difference between @Param(), @Query(), and @Body()?

Part of Pro
09

How do you handle configuration in Nest.js?

Part of Pro
10

How do you return different HTTP status codes in Nest.js?

Part of Pro
11

What is the purpose of the @Global() decorator?

Part of Pro
12

How is Nest.js different from plain Express?

Part of Pro
13

What are pipes in Nest.js and when would you use them?

Part of Pro
Intermediate 31
14

How do you implement request/response logging?

Part of Pro
15

How does dependency injection work in Nest.js?

Part of Pro Visual
16

How do guards work in Nest.js?

Part of Pro
17

What are interceptors in Nest.js, and what is a common use case?

Part of Pro Visual
18

How do you handle exceptions in Nest.js?

Part of Pro
19

How do you implement authentication in Nest.js?

Part of Pro
20

How do you implement custom decorators in Nest.js?

Part of Pro
21

What are the different types of providers in Nest.js?

Part of Pro
22

How do you implement unit testing in Nest.js?

Part of Pro
23

What is the execution order of Nest.js components?

Part of Pro
24

How do you implement caching in Nest.js?

Part of Pro Visual
25

How do you implement file upload in Nest.js?

Part of Pro
26

What is the difference between synchronous and asynchronous providers?

Part of Pro
27

How do you implement rate limiting in Nest.js?

Part of Pro Visual
28

What is the purpose of ExecutionContext?

Part of Pro
29

How do you implement health checks in Nest.js?

Part of Pro
30

What are the different scopes available for providers?

Part of Pro
31

How do you implement WebSocket communication?

Part of Pro Visual
32

How do you implement custom validation pipes?

Part of Pro
33

What is the difference between guards and middleware?

Part of Pro
34

What are the testing utilities provided by Nest.js?

Part of Pro
35

How do you implement request timeouts?

Part of Pro Visual
36

How do you implement API versioning?

Part of Pro
37

How do you implement custom exception filters?

Part of Pro
38

What does ValidationPipe do, and what do its main options do?

Part of Pro Visual
39

When would you switch Nest.js from the Express adapter to Fastify?

Part of Pro
40

How do you generate API documentation in Nest.js?

Part of Pro
41

Why does Nest.js say it can't resolve the dependencies of a provider?

Part of Pro Visual
42

How do you implement role-based access control with guards in Nest.js?

Part of Pro
43

How do you implement streaming responses?

Part of Pro Visual
44

What are some common security practices in Nest.js?

Part of Pro
Expert 6
45

What are microservices in Nest.js?

Part of Pro Visual
46

What are dynamic modules in Nest.js?

Part of Pro
47

What is circular dependency and how do you resolve it?

Part of Pro Visual
48

How do you implement database transactions?

Part of Pro Visual
49

What are the performance optimization techniques in Nest.js?

Part of Pro
50

What is the lifecycle of a Nest.js application?

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for Nest.js? Send them this set.
Quick recap

Nest.js in pictures.

A quick recap of Nest.js in 31 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.

Pro The first chapter is free to play. The other 28 pictures come with Pro.

Get Pro · $10/mo
Pro · $10/mo

44 of 50 Nest.js answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime

Change topic

Pick a different technology or stack. Your current topic stays put until you choose a new one.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git