NestJS

Debugging NestJS apps

Every request your NestJS app handles, with its controller method, exceptions as your filters answer them, queries, Logger lines and @nestjs/schedule jobs.

npm install peekinside
Quick start

PeekInside shows what your NestJS app does with each request: the controller method that handled it, the exception it threw with your TypeScript lines around it, the queries it ran, the APIs it called and the lines your services logged, in a dashboard on your machine. It works with Nest 10 and later, on Express or on Fastify.

import { NestFactory } from '@nestjs/core';
import PeekInside from 'peekinside';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  PeekInside.attach(app); // before app.listen()
  await app.listen(3000);
}
bootstrap();

Attach it before app.listen() (or app.init()): Nest sets up its routes and scheduled jobs then. The same line works with new FastifyAdapter().

What you see for each request#

  • The route and the controller method: GET /orders/:id, handled by OrdersController.findOne.
  • The request and the response: headers, query, route parameters, bodies and status, captured before Express or Fastify reads them, so it doesn't matter where your middleware sits.
  • The exception, with its stack trace mapped to your .ts files through the source maps nest build writes.
  • Its database queries: TypeORM, Prisma, Mongoose, Sequelize and anything else on pg, mysql2 or mongodb, with slow queries and N+1 loops flagged.
  • Its outgoing calls, through HttpService (axios), fetch or any other client on node:http.
  • The lines your services logged with Nest's Logger, as [OrdersService] Charging card, on the request's timeline and on the Logs page.

Exceptions, the way Nest answers them#

Nest answers every error itself, through its exception filters, so PeekInside hooks into the filters rather than into Express or Fastify:

  • An error one of your exception filters catches is recorded as handled, unless the filter hands it to Nest with super.catch().
  • An error that gets Nest's default answer, a 500 logged by ExceptionsHandler, is unhandled.
  • 4xx exceptions (NotFoundException, BadRequestException, UnauthorizedException...) are how your app answers bad requests, and aren't recorded.

Errors in guards, pipes, interceptors and middleware are recorded the same way, and an error in a guard still says which controller method the request was for. Nothing about how your app answers changes.

Nest's Logger#

Lines written with Nest's Logger keep the class that wrote them, and errors keep their stack. Nest's own startup lines (modules loaded, routes mapped) are left out; its warnings and errors aren't. If you give Nest a pino or winston logger (nestjs-pino, nest-winston), its lines are recorded through that logger instead.

@nestjs/schedule jobs#

Every @Cron, @Interval and @Timeout method is a job run on the Jobs page, named after its class and method (ReportsService.sendDigest), or the name you gave it, with its cron expression or interval. Nest's scheduler catches what a method throws and only logs it, so a failing job looks like one that ran fine; PeekInside records the failure, with the exception, and the Schedules view shows a job that misses its run.

A worker made with NestFactory.createApplicationContext() sets up its scheduled jobs while it is created, so create PeekInside first:

const peekInside = new PeekInside();
const worker = await NestFactory.createApplicationContext(WorkerModule);
peekInside.attachTo(worker);

BullMQ processors (@nestjs/bullmq) are job runs too, with their queue, attempt and data.

Laravel Telescope, for NestJS#

If you came to NestJS from Laravel, this is the closest thing to Telescope: requests, exceptions, queries, HTTP client calls, logs, jobs, schedules, dumps and mail. See Laravel Telescope for Node.js for how the two compare.

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: the same pages for your team, 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.