nodejs使用ts
mkdir ts-demo && cd ts-demo && npm init
npm i -D typescript @types/node nodemon ts-node
也可以用
npx tsc --init
命令直接生成一个默认的tsconfig.json也可以如下自己建立一个
{
"compilerOptions": {
"baseUrl": ".",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"outDir": "out",
"paths": {},
"removeComments": false,
"sourceMap": true,
"strict": true,
"target": "esnext"
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
{
"ignore": ["**/*.test.ts", "**/*.spec.ts", ".git", "node_modules"],
"watch": ["src"],
"exec": "ts-node -P tsconfig.json src/app.ts",
"ext": "ts"
}
{
"scripts": {
"dev:server": "nodemon"
}
}
npm run dev:server