nodejs express mongodb typescript 초기세팅 최최최종.txt

SH·2022년 7월 29일
0

서버 세미나

목록 보기
14/14
  1. yarn init

  2. yarn add express dotenv express-validator mongoose
    +) @types/express-serve-static-core, @types/node, cors, mongoose-validator, ts-node, typescript도 추가
    +) npm i로 설정준 게 Dependency에 들어감

  3. yarn add -D @types/node @types/express @types/mongoose nodemon ts-node typescript
    +) 이게 devDependency에 들어가는거
    +) @types/ 이렇게 되어있는게 typescript와 연동 가능

    eslint랑 prettier 쓰려면 아래도 해줘야 함
    yarn add -D eslint
    yarn add -D -E prettier
    yarn add -D eslint-plugin-prettier eslint-config-prettier

  4. $ npx tsc --init
    tsconfig 파일 만들어지면 중간에 뭐 설정 만지는데 이건 그냥 세미나 쇽샥하자,,,

  5. nodemon.json 파일 추가 및 설정

    1. 유튜브 강의 버전
      https://github.com/TomDoesTech/REST-API-Tutorial/blob/main/nodemon.json
    2. 세미나 보일러 플레이트 버전도 있음 참고 (난 이걸로 함)
  1. package.json에 추가
"scripts": {
    "dev": "nodemon",
    "build": "tsc && node dist"
  },
  1. src/config 폴더 만들고 그 안에 index.ts 만들기
index.ts 내용은 세미나 참고
  1. src 파일 바깥에 .env 파일 만들기
  2. loaders 파일 안에 db.ts 파일 만들고 설정
셈나 참고
  1. src/index.ts에서 제대로 돌아가는지 확인
    셈나 코드 복붙하면 routes 폴더 없어서 오류남 이것도 만들어주셈~

ESlint & Prettier 설정
https://feynubrick.github.io/2019/05/20/eslint-prettier.html

profile
블로그 정리안하는 J개발자

0개의 댓글