Debugging Nx NestJS from VSCode

How to set up debugging an Nx NestJS project from VSCode. This debugs a running NestJS instance in attach mode.

TechPublished 1 min read

This explains how to set up debugging an Nx NestJS project from VSCode.
It debugs a running NestJS instance in attach mode.

1. Create launch.json

Create a launch.json file from VSCode's Run and Debug > gear icon.

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach NestJS WS",
      "restart": true,
      "sourceMaps": true,
      "cwd": "${workspaceFolder}/server"
    }
  ]
}

The server in "cwd": "${workspaceFolder}/server" is
the name (folder name) of the NestJS project created with Nx, so change it as appropriate.

2. Start the NestJS project

In the VSCode terminal, run the following command.

nx serve server

3. Start debugging

VSCode's Run and Debug > Start Debugging

img