javascriptnode.jsquery-stringkoakoa-router

Koa router: How to get query string params?


I'm using koa-router.

How can I get the request's query string params?

This is the best I managed to write:

import koaRouter from 'koa-router';

const router = koaRouter({ prefix: '/courses' });

router.get('/', async (ctx) => {
        console.log(ctx.qs["lecturer"]);
    });

but qs is undefined

Any help will be profoundly appreciated!


Solution

  • According to the docs there should be a ctx.request.query that is the query string items represented as an object.