Koa router: How to get query string params?

Alon picture Alon · Apr 6, 2017 · Viewed 41.4k times · Source

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!

Answer

CodingWithSpike picture CodingWithSpike · Apr 6, 2017

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