microsoft / vscode-recipes

MIT License
5.86k stars 577 forks source link

`attach` configuration for Nodemon #332

Closed otowncaleb closed 6 months ago

otowncaleb commented 9 months ago

Is there a way to attach a debugger to a running Node process, such that the debugger re-attaches itself when Nodemon restarts the process on save?

The current recipe recommends an attach configuration but provides only a launch configuration. It seems the attach configuration was removed in order to fix #273.

It would be nice to have an attach configuration for those who wish to start the app in a terminal and run/attach the VS Code debugger only when needed.

otowncaleb commented 9 months ago

This configuration works for attaching to the Node process but the debugger dies on save, presumably due to Nodemon killing the process and starting a new one. Setting restart: true doesn't work, again presumably because it tries to attach to the old process instead of the new one.

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "attach",
      "name": "Node: Nodemon",
      "processId": "${command:PickProcess}"
    }
  ]
}
devopsinvictus commented 6 months ago

npm run debug

otowncaleb commented 6 months ago

omg I can't believe it's that simple...

Is this behaviour documented somewhere in VS Code docs?