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

koa-mysql(二)

时间:2023-04-03 23:21:45 Node.js

路由安装依赖cnpminstallkoa-router--save修改index.jsconstkoa=require('koa');constrouter=require('koa-router')();constapp=newkoa();router.get('/',async(ctx,next)=>{ctx.response.body="

hello,world

"})app.use(router.routes());app.listen(3000);console.log(`appstartatlocalhost:3000`);http://localhost:3000/别页面constkoa=require('koa');constrouter=require('koa-router')();constapp=newkoa();router.get('/',async(ctx,next)=>{ctx.response.body="

你好,世界

"})router.get('/hello',async(ctx,next)=>{ctx.response.body="这是你好页面"})router.get('/hello/:name',async(ctx,next)=>{varname=ctx.params.name;ctx.response.body=`

hello,${name}

`})app.use(router.routes());app.listen(3000);console.log(`appstartatlocalhost:3000`);http://localhost:3000/hellohttp://localhost:3000/hello/biaopost