Version Notes Node.js: Create a projectCreate the following directory structure project ├── src │ └── server.ts ├── package.json └── tsconfig.json
Install DependenciesNotice:
yarn add koa yarn add typescript @tsconfig/node16 @types/node @types/koa concurrently nodemon -D Filling contentsrc/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 Note: The value of the { "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\"" } run All our source code is in the Local development: If there is no Deployment production: execute Referencesmicrosoft/TypeScript-Node-Starter This is the end of this article about nodejs + koa + typescript integration and automatic restart. For more related nodejs koa typescript content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Example of implementing hollow triangle arrow and X icon with after pseudo element
>>: Chinese and English font name comparison table (including Founder and Arphic)
Question: Although the index has been created, wh...
There are many reasons for slow query speed, the ...
Recently, I have done a simple study on the data ...
Based on past experience, taking notes after comp...
This article example shares the specific code of ...
Preface For the permissions of files or directori...
This article introduces the sample code for imple...
This article is welcome to be shared and aggregat...
Six steps of JDBC: 1. Register the driver 2. Get ...
Table of contents 1 Background 2 Create a contain...
This article shares the specific code of Bootstra...
[Problem description] On the application side, th...
Table of contents Brief Introduction setInterval ...
This article uses an example to illustrate the us...
This article is based on the Free Code Camp Basic...