在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
版本说明Node.js: 创建项目创建如下目录结构 project ├── src │ └── server.ts ├── package.json └── tsconfig.json
安装依赖注意:
yarn add koa yarn add typescript @tsconfig/node16 @types/node @types/koa concurrently nodemon -D 填充内容src/server.tsimport Koa from 'koa'; const server: Koa = new Koa(); const port: number = 3000; server.use((ctx: Koa.DefaultContext) => { ctx.body = 'hi koa'; }); server.listen(port, () => { console.log(`Node.js v${process.versions.node}`); }); tsconfig.json注意: { "extends": "@tsconfig/node16/tsconfig.json", "compilerOptions": { "baseUrl": ".", "rootDir": "src", "outDir": "dist", "noImplicitAny": true, }, "include": [ "src/**/*" ] } package.json"scripts": { "build-ts": "tsc", "build": "yarn build-ts", "debug": "yarn build && yarn watch-debug", "serve-debug": "nodemon --inspect dist/server.js", "serve": "node dist/server.js", "start": "yarn serve", "watch-debug": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm:watch-ts\" \"npm:serve-debug\"", "watch-node": "nodemon dist/server.js", "watch-ts": "tsc -w", "watch": "concurrently -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm:watch-ts\" \"npm:watch-node\"" } 运行我们的所有源码在 本地开发:如果没有 部署生产:顺序执行 参考资料microsoft/TypeScript-Node-Starter 到此这篇关于nodejs + koa + typescript 集成和自动重启的文章就介绍到这了,更多相关nodejs koa typescript内容请搜索极客世界以前的文章或继续浏览下面的相关文章希望大家以后多多支持极客世界! |
请发表评论