nest.js로 대충 만들어보는 공연예매, 하며 공부
controller
에서 -> 요청 DTO 유효성 검사service
에서 비즈니스 로직 수행 (예외처리 응답)repository
에서 db
관련 작업controller
로 반환 -> 응답 DTOAPI | method | description |
---|---|---|
/api/signup | POST | 회원가입 |
/api/signin | POST | 로그인 |
/api/users | GET | 회원 조회 |
/api/shows | POST | 공연 등록 |
/api/shows | GET | 공연 조회 |
/api/shows/:showId | GET | 공연 상세 조회 |
/api/shows?keyword=어쩌고 | GET | 공연 검색 |
/api/shows/:showId/seats | GET | 잔여 좌석 확인 |
/api/shows/:showId/seats/:seatId/reservations | POST | 예매하기 |
/api/reservations | POST | 유저 예매내역조회 |
/api/reservations/:reservationId | POST | 상세 예매 내역 조회 |
> npx nest new [projectName]
"scripts": {
"build": "nest build", // dist파일 만들어 빌드
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch", // local 서버에서 실행
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json" // 테스트코드 실행
},
bcrypt
: 패스워드 암호화cross-env
: 윈도우, 맥에서 package.json의 script에 node 명령어 작성 시 공통적으로 처리@nestjs/platform-express
: 프론트랑 통신 편리하게 하는 서버 라이브러리passport
, passport-jwt
, @types/passport-jwt
, @nestjs/passport
, @nestjs/jwt
: JWT토큰 및 검증 시 사용 라이브러리typeorm
, @nestjs/typeorm
: typeORM 라이브러리mysql2
: mysql서버랑 연동하는 라이브러리moment
: 시간관련class-validator
: 유효성 검사nestjs/swagger
, express-basic-auth
, swagger-ui-express
: swaggerAPI 자동화pm2
: 배포환경 테스트// src/app.controller.ts
import { Controller, Get } from '@nestjs/common';
@Controller()
export class AppController {
@Get()
getHello(): string {
return 'Service Working';
}
}
// src/app.module.ts
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
@Module({
imports: [],
controllers: [AppController],
})
export class AppModule {}
참조: https://velog.io/@jangdu/nestjs-Hot-reload-%EC%B4%88%EA%B8%B0%EC%84%A4%EC%A0%95
참고: https://velog.io/@jangdu/nest.js-Logger
express에서 .env를 만지려면 dotenv라이브러리를 설치해서 만졌는데,
nest에서는 config라는것을 제공해서 전역으로 dotenv를 사용할 수 있는 기능을 제공해준다.
> npm i --save @nestjs/config
// app.module.ts
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
@Module({
imports: [ConfigModule.forRoot()],
})
export class AppModule {}
이제 전역에서 process.env어쩌고 쓸 수 있음