NestJS is a structured Node framework using TypeScript decorators, modules, and dependency injection—popular in teams wanting Angular-like architecture on the server.
Building blocks
- Modules — group related controllers and providers
- Controllers — route handlers with decorators (
@Get()) - Providers/Services — injectable business logic
- Pipes — validation/transformation
- Guards — authorization
Conceptual example
@Controller('cats')
export class CatsController {
constructor(private catsService: CatsService) {}
@Get()
findAll() {
return this.catsService.findAll();
}
}
When to choose Nest
Large teams, TypeScript-first codebases, and microservices needing consistent patterns. Express remains fine for small APIs and learning HTTP without ceremony.
Important interview questions and answers
- Q: Nest vs Express?
A: Nest adds structure, DI, and conventions; Express is minimal—Nest builds on Express/Fastify under the hood. - Q: Dependency injection benefit?
A: Testability and swapping implementations (mock repos) without changing controllers.
Self-check
- What three Nest building blocks map to routes, logic, and grouping?
- When would you stay on Express instead?
Interview prep
- NestJS vs Express?
NestJS adds Angular-inspired structure—modules, DI, decorators—on top of Express/Fastify; Express stays minimal and flexible.