미니프로젝트를 시작하기 위해 정말 기본적인 "쇼핑몰"이란 주제로 개발을 시작하려고 한다.
쇼핑몰은 보통 백엔드를 공부할 때 기초적인 api들과 서비스를 확장함에 따라 점점 심화되는 api를 개발할 수 있다는 장ㅇ점이 있어 해당 미니프로젝트 주제로 "쇼핑몰"을 선택하였다.
1. 요구사항 명세서
역할은 이 서비스를 이용할 사용자와 관리자로 나눴다.
사용자의 경우 비회원일 경우 상품에 대한 조회나 장바구니가 가능하나 구매와 찜을 할 수 없다.
관리자의 경우 모든 상품을 조회, 추가, 수정, 삭제할 수 있고, 모든 사용자에 대한 정보를 조회할 수 있다.
2. Github repo 생성
github와 연결하기 위해 사전에 repository를 만든다.
만든 뒤 code를 눌러 해당 repository의 경로를 복사한다.
git clone을 이용하여 해당 레포를 들고와서, 해당 폴더로 이동하여 vscode를 열어준다.
3. NestJS 프로젝트 생성
프로젝트를 시작할 폴더를 생성한 뒤 NestJS CLI를 설치하여 프로젝트를 생성한다.
npm i -g @nestjs/cli # Nest.js CLI 전역 생성
nest new project-name # Nest.js 프로젝트 생성
필자의 경우 TREND_PICK 폴더 아래 trendpick-backend라는 프로젝트를 생성하였다.
Node_modules와 package.json, package-lock.json에 대한 설명은 해당 링크로 https://ha2o.tistory.com/128
4. Prisma 연결
프로젝트 폴더로 이동하여 Prisma와 Prisma CLI를 설치한 뒤 기본 설정 파일을 생성한다.
npm install prisma --save-dev # Prisma 설치
npm i @prisma/client # Prisma CLI 설치
npx prisma init # 기본 설정 파일 생성
Prisma 생성을 한 뒤 prisma 폴더와 .env가 생성되었다.
필자는 MySQL을 사용할 예정으로 "schema.prisma"파일과 ".env"파일을 수정한다.
// schema.prisma
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
# .env
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
DATABASE_URL="mysql://root:1234@localhost:3306/trendpick?schema=public"
5. Github 연결
변경했던 사항들을 추가하고 commit하여 repo에 push한다.
git add .
git commit -m "내용"
git push origin main
Github에 푸쉬되어 연결된 것을 확인할 수 있다.
'Programming > Nest' 카테고리의 다른 글
[NestJS] NestJS와 Prisma (1) | 2024.12.20 |
---|---|
[NestJS] mysql, prisma를 이용한 게시판 CRUD 구현 (1) | 2024.07.16 |
NestJS 설치 및 기본 구성 (0) | 2024.06.22 |