IonicMan
IonicMan

Reputation: 902

koa-router has no functions

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?

Upvotes: 0

Views: 223

Answers (1)

Sebastian Hildebrandt
Sebastian Hildebrandt

Reputation: 2771

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?

Upvotes: 1

Related Questions