NestJS Notebook - Part 1
Master modern backend architecture from first principles. Understand how NestJS organizes scalable server applications through TypeScript decorators, modular boundaries, controller routing, provider services, and automated dependency injection.
- Why NestJS? Structured TypeScript architectural backbone vs Express chaos
- Three-tier flow: Client → Controller (waiter) → Service (chef) → Provider / DB
- Dependency Injection: IoC Container, singletons, and loose coupling water pipe analogy
- HTTP routes: @Controller(), @Get(), @Post(), @Patch(), @Delete(), route decorators
- Production Student API: full CRUD with NotFoundException, DTO patterns, and Postman
import { Controller, Get, Post,
Patch, Delete, Body, Param }
from '@nestjs/common';
import { StudentService }
from './student.service';
@Controller('students')
export class StudentController {
constructor(
private readonly service: StudentService
) {}
@Get()
findAll() {
return this.service.getAll();
}
@Post()
create(@Body() dto: CreateStudentDto) {
return this.service.create(dto);
}
@Patch(':id')
update(
@Param('id') id: string,
@Body() dto: UpdateStudentDto
) {
return this.service.update(id, dto);
}
}