IT/Technology

express, typescript 초기 기본 설정

P.Venti 2023. 1. 10. 21:34

1. express 설치

npm install express

2. typescript 설치

 2.1 typescript 설치 (글로벌)

npm install -g typescript

 2.2 nodejs(express) x typescript

npm install --save-dev typescript ts-node @types/express @types/node

  ts-node : typescript compiler 없이 직접 실행.

 2.3 tsconfig.json 생성

npx tsc --init

 

3. json 파일 수정

 3.1 package.json

"scripts": {
    "build": "tsc -p .",
    "start": "node dist/main.js",
    "dev": "nodemon --watch \"/**/*.ts\" --exec \"ts-node\" main.ts"
  },

 3.2 tsconfig.json (일부)

"compilerOptions": {
	"outDir" : "./dist"
},

  - outDir : 변환된 js파일 내보내는 폴더 지정