nest g controller <name>nest g service <name>nest g class <name> ┌───────────────┬─────────────┬──────────────────────────────────────────────┐
│ name │ alias │ description │
│ application │ application │ Generate a new application workspace │
│ class │ cl │ Generate a new class │
│ configuration │ config │ Generate a CLI configuration file │
│ controller │ co │ Generate a controller declaration │
│ decorator │ d │ Generate a custom decorator │
│ filter │ f │ Generate a filter declaration │
│ gateway │ ga │ Generate a gateway declaration │
│ guard │ gu │ Generate a guard declaration │
│ interceptor │ itc │ Generate an interceptor declaration │
│ interface │ itf │ Generate an interface │
│ middleware │ mi │ Generate a middleware declaration │
│ module │ mo │ Generate a module declaration │
│ pipe │ pi │ Generate a pipe declaration │
│ provider │ pr │ Generate a provider declaration │
│ resolver │ r │ Generate a GraphQL resolver declaration │
│ service │ s │ Generate a service declaration │
│ library │ lib │ Generate a new library within a monorepo │
│ sub-app │ app │ Generate a new application within a monorepo │
│ resource │ res │ Generate a new CRUD resource │
└───────────────┴─────────────┴──────────────────────────────────────────────┘
@Controller : 컨트롤러 지정
@Controller 데코레이터의 인자는 prefix@Controller('app')이라고 했다면 http://localhost:3000/hello -> http://localhost:3000/app/hello 로 접근@Controller 의 host 속성으로 하위 도메인 처리 설정@Controller({ host: 'api.example.com' }) // 하위 도메인 요청 처리 설정@Param : 요청 파라미터 처리
@Header : 응답에 커스텀 헤더 추가
@Header('Custom', 'Test Header')
@Redirect : 리다이렉트
@Redirect('https://nestjs.com', 301)@Get('docs')
@Redirect('https://docs.nestjs.com', 302)
getDocs(@Query('version') version) {
if (version && version === '5') {
return { url: 'https://docs.nestjs.com/v5/' };
}
}
@Body : HTTP Body 처리
@Injectable : 주입될 수 있는 프로바이더로 지정
@Inject : 생성자가 아닌 필드 주입
@Inject 를 사용하는 것이 편리export class BaseService {
@Inject(ServiceA) private readonly serviceA: ServiceA;
...
}