프로젝트를 만들고 싶은 폴더의 위치에서 ‘npm init’을 입력해준다.
그러면 package.json이 생성될 것이다.
그 후 필요한 모듈을 설치하여 준다.
npm init
npm i -D express typescript ts-node nodemon ejs @types/node @types/express
typescript 컴파일 명령어인 tsc를 이용하여 tsconfig.json 파일을 생성해줍니다.
tsc --init
그 후 express 서버를 돌리기 위한 설정을 아래와 같이 바꿔줍니다.
(outDir, rootDir, moduleResolution 을 활성화 후 outDir, target의 값을 수정해준다.)
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"rootDir": "./src",
"outDir": "dist",
"moduleResolution": "node",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"include": ["./src/**/*"],
"exclude": ["node_modules"]
}
package.json 파일에서 scripts의 내용을 수정해줍니다.
"scripts": {
"start": "node dist/app.js",
"dev": "nodemon app.ts",
"build": "tsc -p .",
"test": "echo \\"Error: no test specified\\" && exit 1"
},