Debugging Fastify apps
A free local dashboard for Fastify: every request with its route, the error it threw, its database queries, outgoing calls and pino logs.
npm install peekinsidePeekInside shows what your Fastify app does with each request: the route it matched, 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. Fastify has no free local dashboard of its own; this is one, with one line.
import Fastify from 'fastify';
import PeekInside from 'peekinside';
const fastify = Fastify();
PeekInside.attach(fastify); // before fastify.listen()
fastify.get('/orders/:id', async (request) => getOrder(request.params.id));
await fastify.listen({ port: 3000 });
Attach it before fastify.listen() (or fastify.ready()): it adds hooks, and Fastify only takes hooks until the app is ready. PeekInside prints the link to its dashboard when the app starts.
What you see for each request#
- The route Fastify matched, as you declared it (
GET /orders/:id), with its parameters. The Routes page groups requests by it, with each route's traffic, error rate and response times. - The request and the response: headers, query, bodies (captured as Fastify parses them, so your schemas and content-type parsers are untouched) and status.
- The error it threw, with its stack trace and your source lines, TypeScript included.
- Its database queries (pg, mysql2, Prisma, MongoDB, Mongoose and the ORMs on them), with slow queries and N+1 loops flagged; its outgoing calls; and the lines it logged with pino (Fastify's own logger), winston or the console.
Fastify errors#
Errors from route handlers and hooks are recorded from Fastify's onError hook, which never changes the answer:
- With your own error handler (
fastify.setErrorHandler()), an error is recorded as handled. - With Fastify's default handler, it's unhandled.
Validation errors and other 4xx answers aren't recorded: they're how your app answers bad requests.
Logs#
Fastify logs with pino, and PeekInside records what pino writes: request.log.info(...) lines appear on the request's timeline and on the Logs page, with their structured data, and lines a logger turned off aren't recorded.
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. Using Fastify through NestJS? See NestJS.
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.