Error: Cannot find module 'koa-router'
koa-router
!== koa-route
# ✅ install OK 👍
$ yarn add koa-router
https://www.npmjs.com/package/koa-router
# ❌ install by mistake 👎
$ yarn add koa-route
https://www.npmjs.com/package/koa-route
koa-route 👎💩❌
$ yarn add koa-route
# OR
$ npmi koa-route
const log = console.log;
const fs = require('fs');
const koa = require('koa');
const router = require('koa-router');
const app = new koa();
// const app = koa();
const routers = router();
routers.get('/things/:name/:id', sendIdAndName);
function *sendIdAndName(){
this.body = 'id: ' + this.params.id + ' and name: ' + this.params.name;
};
app.use(routers.routes());
app.listen(3000);
https://www.tutorialspoint.com/koajs/koajs_url_building.htm
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!