출처 링크
https://medium.com/geekculture/nest-js-architectural-pattern-controllers-providers-and-modules-406d9b192a3a
Nest의 역사
- 2017년 개발
 
- Kamil Myśliwiec 에 의해 창조 ( 
 
- Angular Architecture 의 스타일 과 구조를 참조
 
- MVC Design Pattern 을 기본 Pattern 으로 함
 
Nest의 특징
- Typescript 지원
 
- Node 위에 구현된 Layer
 
- Server Side Application
 
- Module 단위로 묶어서 관리
 
Nest Controller
- Application 에서 요청을 받고 Routing 처리하는 부분
 
import { Controller, Get } from '@nestjs/common';
import { CatsService } from '../services/cats.service';
@Controller('cats')
export class CatsController {
  constructor(private readonly catsService: CatsService) {}
  @Get('allcats')
  getCats(): string {
    return this.catsService.getAllCats();
  }
  @Get('onecat')
  getOneCat(): string {
    return this.catsService.getOneCat();
  }
}
- Controller Decorator 로 해당 class 가 Controller임을 선언
 
- Get Decorator 로 해당 경로에 들어오면 해당 Function이 처리함을 선언
 
- D.I 를 통해  catsService 를 Instance 할당 하지 않아도 자동으로 주입된 Instance 참조
 
Nest Service
import { Injectable } from '@nestjs/common';
@Injectable()
export class CatsService {
  getAllCats(): string {
    return 'Get all cats!';
  }
  getOneCat(): string {
    return 'Get one cat!';
  }
}
- Injectable Decorator 로 해당 Class 가 주입 가능한 Provider 임을 선언
 
Nest Module
- Controller 와 Provider 를 결합하여 Application을 Instance 가능하게 하는 부분
 
- Module 을 통해 Application Graphe 를 만들어감.
 
import { Module } from '@nestjs/common';
import { CatsController } from './controllers/cats.controller';
import { CatsService } from './services/cats.service';
@Module({
  controllers: [CatsController],
  providers: [CatsService],
})
export class CatsModule {}
- Moudle Decorator를 통해 해당 Class 가 Module 임을 선언
 
- controllers 해당 Module에 포함할 Controller 를 선언
 
- providers : 해당 Module에 포함할 Provider(service,Factory,Value등) 를 선언