NestJS는 Node.js 서버 어플리케이션을 구축하기 위한 프레임워크
기존에 있던 Node.js 서버 어플리케이션의 추상화 계층이 없다는 단점을 보완하기 위해 제작됨
기본적으로 Express를 사용하지만, Fastify를 사용할 수도 있음
들어오는 요청을 처리하고 클라이언트에 응답을 반환하는 역할
@Controller() 데코레이터를 사용해 라우팅 가능
import { Controller, Get } from '@nestjs/common';
@Controller('cats')
export class CatsController {
@Get()
findAll() {
return 'This action returns all cats';
}
}
각 요청의 인자에 데코레이터를 사용해 요청 시 전송된 값을 받아올 수 있음
- @Request(), @Req() : req
- @Response(), @Res() : res
- @Next() : next
- @Session() : req.session
- @Param(key?: string) : req.params / req.params[key]
- @Body(key?: string) : req.body / req.body[key]
- @Query(key?: string) : req.query / req.query[key]
- @Headers(name?: string) : req.headers / req.headers[name]
- @Ip() : req.ip
- @HostParam() : req.hosts