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 發佈文章使用:只允許註冊用戶纔可以訪問!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章