NestJS

Set up debugger in a NestJS project.

Last updated March 19, 2026

NestJS

This guide covers adding debugger to a NestJS project. The setup takes two steps.

NestJS official docs

Feature Support
Server console Yes
Server errors Yes
HTTP requests Yes
Browser script injection Manual

Install

npm install -D @ephem-sh/debugger

1. Initialize and apply middleware

In your src/main.ts, call initDebugger and apply the middleware via app.use():

import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import { initDebugger, DebuggerMiddleware } from '@ephem-sh/debugger/nest'

initDebugger({ port: 3000 })

async function bootstrap() {
  const app = await NestFactory.create(AppModule)

  const mw = new DebuggerMiddleware()
  app.use((req, res, next) => mw.use(req, res, next))

  await app.listen(3000)
}
bootstrap()

The middleware is applied at the Express layer (via app.use()) rather than via MiddlewareConsumer so it intercepts all requests including /_/d.js and /_/d.

2. Add script tags

Add script tags before </body> in your HTML templates:

<script>window.__DEBUGGER_INGEST_URL__="/_/d";</script>
<script src="/_/d.js" defer></script>

Verify

npm run start:dev
npx dbg status
pnpm dlx dbg status
bun x dbg status
yarn dlx dbg status
npx dbg browser console
pnpm dlx dbg browser console
bun x dbg browser console
yarn dlx dbg browser console

Full example

See the complete working example at examples/node/nest.

Search Documentation

Search for pages and content