Error: Cannot find module 'koa-router'


Error: Cannot find module 'koa-router'

image

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 发布文章使用:只允许注册用户才可以访问!



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM