Koa

Debugging Koa apps

Every request your Koa app handles, with the error it threw, its database queries, outgoing calls and logs, in a free dashboard on your machine.

npm install peekinside
Quick start

PeekInside shows what your Koa app does with each request: the request and the response, the error it threw with your lines of code around it, the database queries it ran, the APIs it called and what it logged, in a dashboard on your machine. It takes one line.

import Koa from 'koa';
import PeekInside from 'peekinside';

const app = new Koa();
PeekInside.attach(app);

app.use(router.routes());
app.listen(3000);

Start your app as usual: PeekInside prints the link to its dashboard. Request bodies are captured as your app reads them, whether koa-bodyparser (or @koa/bodyparser) runs before PeekInside's middleware or after it.

What you see for each request#

  • The request and the response: method, URL, headers, query, bodies and status, with its duration.
  • The error it threw, with its stack trace and your source lines, TypeScript included through source maps.
  • Its database queries (pg, mysql2, Prisma, MongoDB, Mongoose, and Knex, Sequelize, TypeORM, Drizzle or Kysely on top of them), with slow queries and N+1 loops flagged.
  • Its outgoing calls, through axios, got and the rest of node:http, or fetch.
  • What it logged, with the console, pino or winston, on the request's timeline.

Koa errors#

PeekInside records the errors thrown by your middleware and routes, and tells apart the ones your app answers from the ones it doesn't:

  • An error Koa's default handler answers, with a 500, is unhandled.
  • An error your own error-handling middleware answers is handled: one registered before PeekInside's middleware (the error passes PeekInside on its way out), or one anywhere that reports what it answered with ctx.app.emit('error', err, ctx), as Koa suggests.

Errors with a 4xx status, such as ctx.throw(404), aren't recorded: they're how your app answers bad requests. Koa answers and logs everything exactly as before; PeekInside adds no 'error' listener, since that would stop Koa's own logging. Crashes (uncaught exceptions and unhandled rejections) are recorded too, with the request they happened in.

Routes and users#

The Routes page lists every route with its traffic, error rate and response times, ids in paths folded together (/orders/42 and /orders/43 are both GET /orders/:id). Call PeekInside.setUser(ctx.state.user) once your app knows who the request is for, and every request and error says so.

In production#

The local dashboard is off when NODE_ENV is production. On your servers, the same line sends to PeekInside Cloud when PEEKINSIDE_API_KEY is set, encrypted end to end.

Try it on your app

Install the package, add PeekInside.attach(app), and start your app as usual: it prints the link to its dashboard. Free, no account, and your data stays on your machine. On your servers, the same line reports to PeekInside Cloud once it has an API key.