Skip to content
jshacks.dev
Debugging

Attach VS Code to a running Node.js process

Attach the VS Code debugger to a Node.js process that is already running, using --inspect or a SIGUSR1 signal and an attach launch configuration.

1 min read
Summarize in AI

A server is already running, and you cannot restart it with the debug flag. Node.js can open its inspector on request when it receives SIGUSR1, on Linux and macOS.

Shell
kill -USR1 12345

The process, whose id here is 12345, prints this to its own output:

Text
Debugger listening on ws://127.0.0.1:9229/3b0a8d5e-7c1f-4a62-9f0d-5e2b1c4a6d90
For help, see: https://nodejs.org/en/docs/inspector

Then add an attach configuration to VS Code and start it from the Run panel:

.vscode/launch.jsonJSON
{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Attach to Node.js",
      "port": 9229,
      "restart": true
    }
  ]
}

Breakpoints set in the editor now bind to the running process. With restart enabled, the debugger reconnects after a restart. The attach options are described in the VS Code Node.js debugging guide.

For a process you start yourself, use node --inspect app.js. Pausing a live production process stops its requests, so use this on staging or a copy.

Also inNode.js
Share

More snippets

Testing

Group tests with describe in node test

Group related tests with describe and it from node:test, nest suites, and run setup with beforeEach, all without installing a framework.

1 min read
Debugging

Group related logs with console.group

Indent related console output under a label with console.group and console.groupEnd, so interleaved logs from one request stay readable in Node.js 24.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.