Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the VS Code debugger attach to an already running node process?

How is Visual Studio Code debugger able to attach to a already running node process?

I simply used npm start to run my node application and then use the VS Code "attach to process Id" launch configuration to start the debugger. I didn't had to start my application with --inspect or --debug flag. How is this actually working?

like image 278
Queston02 Avatar asked Sep 06 '25 23:09

Queston02


1 Answers

As can be found in the nodejs docs:

Node.js will also start listening for debugging messages if it receives a SIGUSR1 signal. (SIGUSR1 is not available on Windows.) In Node.js 7 and earlier, this activates the legacy Debugger API. In Node.js 8 and later, it will activate the Inspector API.

VS Code sends SIGUSR1 to the process. From the VS Code docs:

the debugger tries to attach to this process after having sent a USR1 signal. With this setting, the debugger can attach to an already running process that was not started in debug mode.

like image 52
rckrd Avatar answered Sep 10 '25 14:09

rckrd