1. 강의 목표

이 강의에서는 NestJS 애플리케이션의 기본 구조와 주요 구성 요소인 Module, Controller, Service 등 각 클래스의 역할과 사용 방법을 이해합니다.

2. NestJS 프로젝트 구조

NestJS는 모듈화된 구조를 기반으로 하며, 다음과 같은 주요 구성 요소로 나뉩니다:

전체적인 프로젝트 구조는 다음과 같습니다:

src/
|-- app.module.ts
|-- app.controller.ts
|-- app.service.ts
|-- modules/
    |-- user/
        |-- user.module.ts
        |-- user.controller.ts
        |-- user.service.ts
        |-- user.entity.ts
        |-- user.repository.ts
    |-- auth/
        |-- auth.module.ts
        |-- auth.controller.ts
        |-- auth.service.ts
        |-- auth.entity.ts
        |-- auth.repository.ts

3. Module (모듈)

개념

역할

코드 예시

// user.module.ts
import { Module } from '@nestjs/common';
import { UserController } from './user.controller';
import { UserService } from './user.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserEntity } from './user.entity';
import { UserRepository } from './user.repository';

@Module({
  imports: [TypeOrmModule.forFeature([UserEntity])],
  controllers: [UserController],
  providers: [UserService, UserRepository],
  exports: [UserService],
})
export class UserModule {}

4. Controller (컨트롤러)

개념