当前位置: 首页 > 后端技术 > Node.js

Node.js+koa2

时间:2023-04-04 01:07:29 Node.js

constKoa=require('koa')constapp=newKoa()constbodyParser=require('koa-bodyparser')app.use(bodyParser())app.use(async(ctx)=>{if(ctx.url==='/'&&ctx.method==='GET'){lethtml=`

这是演示

用户名:

年龄:

网站

提交`ctx.body=html}elseif(ctx.url==='/'&&ctx.method==='POST'){letpostData=ctx.request.body;ctx.body=postData}else{ctx.body='

Notfind

'}})app.listen(3000,()=>{console.log('demoisrun')})github地址:https://github.com/Rossy11/节点