搭建Koa+Typescript

1.使用npm init -y 初始化一个项目

2.安装依赖

 npm i --save-dev @types/node

 npm i --save-dev @types/koa

 npm i typescript ts-node koa nodemon

3.配置package.json 如下

{
  "name": "XXX",
  "version": "1.0.0",
  "description": "",
  "main": "index.ts",
  "scripts": {
    "dev": "nodemon && ts-node index.ts"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "koa": "^2.13.4",
    "ts-node": "^10.9.1",
    "typescript": "^4.8.2"
  },
  "devDependencies": {
    "@types/koa": "^2.13.5",
    "@types/node": "^18.7.13"
  }
}

4.创建index.ts文件

import Koa from "koa";

const app = new Koa();

app.listen("3000", () => {
  console.log("服务器启动");
});

5. npm run dev 启动项目,修改代码就可以观察到效果

你可能感兴趣的:(typescript,javascript,npm)