
NestJS의 모듈(module) 개념 및 module 정의하기
BE/NestJS2023. 11. 17. 23:15NestJS에서 Module이란
@Module
데코레이터가 붙어있는 class이며, NestJS에는 반드시 1개 이상의 module이 필요합니다. 모듈은 밀접하게 관련되어 있는 기능들을 모아둔 것으로, 보통 기능(feature) 별로 모듈을 생성합니다. 예를들어, UserModule, BoradModule 등...
그리고, 모듈은 싱글톤(Singleton)으로 만들어지기 때문에 여러 모듈간에 쉽게 동일한 인스턴스를 공유할 수 있습니다.
Module 정의하기
NestJS는 재밌는게 파일을 직접 만들고 타이핑하지 않아도, 손쉽게 NestJS cli로 모듈을 만들 수 있습니다. nest g module <모듈명>
명령어를 사용해봅시다.
nest g module boards
그리고, 루트 모듈인 AppModule의 imports 부분에도 방금 만든 BoardsModule이 추가가 됩니다.
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { BoardsModule } from './boards/boards.module';
@Module({
imports: [BoardsModule], // 자동으로 추가 됨
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
NestJS 관련 글
NestJS 컨트롤러(Controller) 개념 및 정의하기
NestJS의 컨트롤러(Controller) NestJS에서 controller는 다른 서버 프레임워크와 동일하게, 클라이언트로부터 들어오는 요청(Request)을 라우팅하고 응답(Response)하는 역할을 합니다. 컨트롤러를 정의하기
bluemiv.tistory.com
NestJS에서 서비스(Service) 개념 및 서비스 생성하기
서비스(Service)란 서비스는 NestJS에서만 사용하는 개념은 아니고, 소프트웨어 개발시 공통적으로 사용하는 개념입니다. 서비스는 보통 복잡한 비지니스 로직 또는 데이터베이스 관련된 로직을 처
bluemiv.tistory.com
NestJS Pipe를 이용하여 데이터 변환 및 검증
파이프(Pipes) NestJS에서는 파이프(pipe)를 이용하여 요청의 데이터를 변환(transformation)하거나 검증(validation)을 할 수 있습니다. 파이프도 서비스와 같이 @Injectable() 데코레이터를 사용해서 구현합니
bluemiv.tistory.com
Reference
Documentation | NestJS - A progressive Node.js framework
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Rea
docs.nestjs.com
'BE > NestJS' 카테고리의 다른 글
NestJS + postgres + typeorm 연동하기 (서버 DB 연결) (0) | 2023.11.21 |
---|---|
NestJS Pipe를 이용하여 데이터 변환 및 검증 (1) | 2023.11.20 |
NestJS에서 서비스(Service) 개념 및 서비스 생성하기 (0) | 2023.11.19 |
NestJS 컨트롤러(Controller) 개념 및 정의하기 (0) | 2023.11.17 |
NestJS로 프로젝트 생성 및 서버 개발하기 (0) | 2023.11.17 |
IT 기술에 대한 글을 주로 작성하고, 일상 내용, 맛집/숙박/제품 리뷰 등 여러가지 주제를작성하는 블로그입니다. 티스토리 커스텀 스킨도 개발하고 있으니 관심있으신분은 Berry Skin을 검색바랍니다.
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!