각종 패키지 설치
yarn add @nestjs/typeorm typeorm pg
혹은
npm i @nestjs/typeorm typeorm pg
typeorm 과 nestjs에서 사용할 typeorm 그리고 pg라는 posgres 패키지를 설치한다.
서버 실행
yarn start:dev
혹은
npm run start:dev
모듈 세팅
생성된 NestJS의 파일 중 app.module.ts 로 이동한다.
TypeOrmModule.forRoot()
TypeORM과 NestJS를 연결하는 연결고리(설정)이다.
type: 연결할 SQL
host: 연결할 주소
port: 연결할 포트
username, password, database: postgres에서 세팅한 것으로 설정
entities: 모델 (테이블에 해당)
synchronize: 서버와 DB를 동기화할지 여부 (프로덕션 혹은 릴리즈에선 false하여야 한다.)
위와 같이 설정한다면 NestJS에서 TypeORM을 사용할 수 있게 된다.
'NestJS' 카테고리의 다른 글
TypeORM - Repository 주입하기 (0) | 2025.02.24 |
---|---|
TypeORM - Entity로 테이블 생성하기 (0) | 2025.02.24 |
VCS에서 PostgreSQL 툴 사용하기 (0) | 2025.02.24 |
Docker Compose 사용 및 Postgres 설치 (0) | 2025.02.24 |
Docker 설치 (0) | 2025.02.24 |