前言
前段时间用node写了个工具——主要用于系统内部的一些配置,也是第一次用node。
下面是构建一个简单工程的情况。
构建Node
相关包
- koa
- @koa/router
- koa-bodyparser
关于热更新
nodemon
npm install nodemon -g
关于调试
IDE是使用的vscode,
launch.json配置
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "启动程序",
"program": "${workspaceFolder}/app.js",
"runtimeExecutable": "nodemon",
"restart": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
node app
const Koa = require("koa");
const bodyParser = require("koa-bodyparser");
const Router = require("@koa/router");
// 创建一个Koa对象表示web app本身:
const app = new Koa();
const router = new Router();
app.use(bodyParser());
router.post("test", async (ctx) => {
const { params } = ctx.request.body;
ctx.response.body = { code: 0, data: 0 };
});
app.use(router.routes());
// 在端口233监听:
app.listen(233);
console.log("app started at port 233...");
在vscode上点击debugger就可以进行调试开发了
网友评论