TIL
로그인, 회원가입 및 결제 - DevCamp 1일차
용찬
2024. 3. 4. 20:12
오늘 한 일
yarn과 npm의 차이점 알아보기.
2024.03.04 - [JS] - NPM과 yarn
nest.js와 typeORM 알아보기
2024.03.04 - [JS] - Nest.js와 TypeORM
프로젝트 세팅하기
앞으로 진행할 프로젝트에 앞서 기술스택을 확인 후 세팅하기
기술스택 🛠️
TypeScript + NestJS + SWC
Yarn berry + Plug'n'Play + Zero-Install
TypeORM + PostgreSQL
Joi
Jest
yarn으로 nest 프로젝트 시작하기
nest new [프로젝트명] => yarn 선택
프로젝트에 필요한 패키지 다운로드 받기
yarn add @nestjs/typeorm typeorm argon2 pg joi
jest, Yarn Berry, Plug`n`Play, Zero-Install 는 nest new로 프로젝트를 시작하면 기본 설치 되어있다.
typeORM + PostgreSQL 연결 ( local환경 )
import { Injectable } from '@nestjs/common';
import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from '@nestjs/typeorm';
import { ConfigService } from '@nestjs/config';
@Injectable()
export class TypeOrmConfigService implements TypeOrmOptionsFactory {
constructor(private readonly configService: ConfigService) {}
createTypeOrmOptions(): TypeOrmModuleOptions {
return {
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: '1234aaaa',
database: 'postgres',
entities: [],
synchronize: true,
logging: true,
};
}
}
ormconfig.ts
typeORM을 클래스 기반 설정을 통해 ormconfig.ts를 인터페이스 구현
클래스 기반 설정을 사용, 동적으로 인터페이스를 생성하고 이는 환경에 따라 설정을 변경할 수 있는 장점이 있다.