All questions
Showing of 50Explain the core building blocks of a Nest.js application.
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:
Last attempt -
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.
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 ↓
What are decorators in Nest.js, and what are some examples?
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:
Last attempt -
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.
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 ↓
What is the difference between @Injectable() and @Controller()?
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:
Last attempt -
@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.
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 ↓
Explain modules in Nest.js and their purpose.
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:
Last attempt -
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
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 ↓
What is middleware in Nest.js and how do you implement it?
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:
Last attempt -
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.
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 ↓
What are DTOs and why are they important?
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:
Last attempt -
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.
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 ↓
How do you connect to a database in Nest.js?
What is the difference between @Param(), @Query(), and @Body()?
How do you handle configuration in Nest.js?
How do you return different HTTP status codes in Nest.js?
What is the purpose of the @Global() decorator?
How is Nest.js different from plain Express?
What are pipes in Nest.js and when would you use them?
How do you implement request/response logging?
How does dependency injection work in Nest.js?
How do guards work in Nest.js?
What are interceptors in Nest.js, and what is a common use case?
How do you handle exceptions in Nest.js?
How do you implement authentication in Nest.js?
How do you implement custom decorators in Nest.js?
What are the different types of providers in Nest.js?
How do you implement unit testing in Nest.js?
What is the execution order of Nest.js components?
How do you implement caching in Nest.js?
How do you implement file upload in Nest.js?
What is the difference between synchronous and asynchronous providers?
How do you implement rate limiting in Nest.js?
What is the purpose of ExecutionContext?
How do you implement health checks in Nest.js?
What are the different scopes available for providers?
How do you implement WebSocket communication?
How do you implement custom validation pipes?
What is the difference between guards and middleware?
What are the testing utilities provided by Nest.js?
How do you implement request timeouts?
How do you implement API versioning?
How do you implement custom exception filters?
What does ValidationPipe do, and what do its main options do?
When would you switch Nest.js from the Express adapter to Fastify?
How do you generate API documentation in Nest.js?
Why does Nest.js say it can't resolve the dependencies of a provider?
How do you implement role-based access control with guards in Nest.js?
How do you implement streaming responses?
What are some common security practices in Nest.js?
What are microservices in Nest.js?
What are dynamic modules in Nest.js?
What is circular dependency and how do you resolve it?
How do you implement database transactions?
What are the performance optimization techniques in Nest.js?
What is the lifecycle of a Nest.js application?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
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.
Nest.js cheatsheet
- Modules & controllers01
- Routes & request data02
- Injection & providers03
- The request pipeline04
- Pipes, validation & errors05
- Login, roles & security06
- Databases, config & caching07
- Unit & end-to-end tests08
- Production & performance09
- WebSockets & microservices10
- The model11
- + 5 more inside
This picture is part of Pro. The first chapter is free to play; the other 28 pictures come with Pro.
Get Pro · $10/mo Already Pro? Sign in44 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.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.