개발/NestJs 10

5. 스케쥴링

5. 스케쥴링 1) 설치 yarn add @nestjs/schedule yarn add @types/cron 2) 활용 nest g mo job nest g s job 모듈은 아래와같이 작성한다. @Module({ imports: [ScheduleModule.forRoot()], providers: [JobService], }) export class JobModule {} 서비스는 아래와같이 작성한다 @Injectable() export class JobService { @Cron('10 * * * * *') handleCron() { console.log('Called when the current second is 45'); } @Interval(10000) handleInterval() { con..

개발/NestJs 2023.10.20

4. 로그

4. 로그 1) 설치 yarn add nest-winston yarn add winston yarn add winston-daily-rotate-file 2) 설정 로그레벨은 아래와 같다 { error: 0, warn: 1, info: 2, http: 3, verbose: 4, debug: 5, silly: 6 } 아래처럼 main.ts에 로그저장형태와 로그레벨 등을 설정한다 import { utilities, WinstonModule } from 'nest-winston'; import { format, transports } from 'winston'; import 'winston-daily-rotate-file'; const app = await NestFactory.create(AppModule,..

개발/NestJs 2023.10.20

3. 외부환경파일

3. 외부환경파일 1) 설치 @nestjs/config : 설정 파일을 외부에서 가져오기 위한 nestjs에서 제공되는 모듈 cross-env : os에 종속되지 않고, 플랫폼 표준화를 하기위해 필요한 라이브러리 joi : 형식에 대한 유효성 검사 아래와같이 설치한다 yarn add @nestjs/config yarn add cross-env yarn add joi 2) cross-env로 환경변수 주입 package.json에 cross-env NODE_ENV=실행환경 추가 "start:dev": "cross-env NODE_ENV=dev nest start --watch", "start:prod": "cross-env NODE_ENV=prod node dist/main", 3) @nestjs/conf..

개발/NestJs 2023.10.20

2. 데이터베이스

2. 데이터베이스 (오라클 기준) 1) TypeORM 설치 오라클 연결시 Oracle Client 설치가 필요하다 (https://www.oracle.com/kr/database/technologies/instant-client/downloads.html) 그후 아래와 같이 typeORM을 다운로드한다 yarn add oracledb yarn add @nestjs/typeorm typeorm oracle 설치시 문제가 발생한다면 yarn 및 npm 버전업그레이드를 고려해본다 포스트그래스시 yarn add pg yarn add @nestjs/typeorm typeorm postgres 2) 데이터베이스 접속정보 설정 app.module.ts에 접속할 데이터베이스정보를 입력한다 imports: [ TypeO..

개발/NestJs 2023.10.20

1. 프로젝트 생성과 구성

1. 프로젝트 생성과 구성 1) 프로젝트 생성 $ yarn add @nestjs/cli $ nest new 프로젝트명 (yarn선택) 2) Nest 기본구성 모듈 $ nest g mo module-name 외부로 서비스를 공개하고 싶을경우 export 추가 @Module({ controllers: [CatsController], providers: [CatsService], exports: [CatsService], }) export class CatsModule {} 컨트롤러 $ nest g co controller-name 서비스 $ nest g service service-name 3) Nest 응용구성 미들웨어 $ nest g middleware middleware-name 적용시 모듈을 아래와같..

개발/NestJs 2023.10.09