<aside> 💡 nginx를 사용하고 있으므로 pm2에서는 express 실행 만을 담당한다.
</aside>
pm2 install typescript
를 통해 pm2 start ~~
로도 서버를 실행할 수 있지만
배포를 할 예정이므로 프로젝트 코드 빌딩을 통해 배포하였다.현재 프로젝트의 Express의 실행 파일은 app.ts
이다.
tsc (typescript 컴파일러)를 통해 tsconfig.json
설정대로 js파일로 빌딩한다.
(⚠주의!!!!!!!!!!!!!!!!!!! json 파일에 주석을 넣지 마시오)
build
폴더에 빌딩 된 코드가 모여있다.
현재 tsconfig-paths 라이브러리를 이용해 typescript의 alias를 지원하고 있으므로 이를 설정하는 tsconfig-paths-bootstrap.js
를 함께 실행해야 한다.
// tsconfig-paths-bootstrap.js
const tsConfig = require('./tsconfig.json');
const tsConfigPaths = require('tsconfig-paths');
tsConfigPaths.register({
baseUrl: tsConfig.compilerOptions.outDir,
paths: tsConfig.compilerOptions.paths,
});
최종적인 PM2 실행을 한다.
pm2 start ./build/app.js --node-args="-r ./tsconfig-paths-bootstrap.js"
back에서 typeScript를 사용하려면 트랜스파일링(JS) 작업이 필요함
→ tsc를 이용한 빌드 후 실행