프로젝트 폴더를 생성후 npm init or yarn init을 통해 package.json 파일을 생성
npm init or yarn init
tsc --init
TypeScript 컴파일러에 --init 적용해서 typescript 프로젝트를 initialize 할 수 있습니다.
yarn add -D typescript nodemon ts-node @types/node
yarn add express
yarn add -D @types/express
설치 확인
"scripts": {
"start": "nodemon --exec ts-node src/index.ts"
},
console.log('Hello TypeScript node')
yarn add -D tsconfig-paths
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node" /* Skip type checking all .d.ts files. */,
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"skipLibCheck": true,
"baseUrl": ".",
/** 절대 경로 설정 */
"paths": {
"@src/*": ["src/*"]
}
},
"exclude": ["node_modules"],
"include": ["src"]
}
"scripts": {
"dev": "nodemon --watch 'src/**/*.ts' --exec ts-node -r tsconfig-paths/register src/app.ts",
},
yarn add dotenv
ex)
DB_HOST=localhost
DB_USER=root
DB_PASS=1234
"scripts": {
"dev": "NODE_ENV=dev nodemon --watch 'src/**/*.ts' --exec ts-node -r tsconfig-paths/register src/app.ts",
},
yarn add cross-env
"scripts": {
"dev": "cross-env NODE_ENV=dev nodemon --watch 'src/**/*.ts' --exec ts-node -r tsconfig-paths/register src/app.ts",
},
개발자로서 성장하는 데 큰 도움이 된 글이었습니다. 감사합니다.