0

I tried to import the koa-router into my nodejs app like this:

enter image description here

but when checking the code completion, there is no get method to be found. Or any other method.

I installed it using npm install koa-router but apparently something is not working.

Can someone help me?

IonicMan
  • 743
  • 1
  • 12
  • 31
  • According to the documentation, `router` is a class that needs to be instantiated. [Read the docs](https://github.com/koajs/router/blob/HEAD/API.md), don't try to guess how the library works. – Evert Aug 03 '21 at 17:03

1 Answers1

1

koa-router is now @koa/router. In the documentation you should find this:

This module is forked from the original koa-router due to its lack of activity.

So your code should look like this:

const Koa = require('koa');
const Router = require('@koa/router');

const app = new Koa();
const router = new Router();

router.get('/', (ctx, next) => {
  // ctx.router available
});

This way I guess, your code completion should work. Can you confirm this?

Sebastian Hildebrandt
  • 2,661
  • 1
  • 14
  • 20