Search code examples
javascriptkoa

Using async/await in koa middlewares


This does not work:

app.use(async function () {
   await something();
});

// AssertionError: app.use() requires a generator 

While this works OK:

router.get('/', async function () {
    await something();
});

Any reason for that?


Solution

  • You must be using Koa 1 - try npm install koa@next.