Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make vscode stop both nodemon and npm after stopping the debugger?

I'm running the following launch.json configuration and package.json script and it's working very well, I'm able to run the app and debug it. However, when I hit the "stop" button in the vscode debugger, nodemon is stopped but the npm process (and the entire app) keeps running. If I modify a file and save it then nodemon comes back up again (as expected). The only way to really stop the app is to hit ctrl+c in the terminal. Is there a way to stop both processes once the debugger stop button is clicked?

package.json script

"scripts": {
 "start": "node app",
 "debug": "nodemon --experimental-modules --inspect ./bin/www.mjs"
}

launch.json config

{
 "type": "node",
 "request": "launch",
 "name": "Launch via NPM",
 "runtimeExecutable": "npm",
 "runtimeArgs": [
  "run-script",
  "debug"
 ],
 "port": 9229,
 "restart": true,
 "console": "integratedTerminal"        
}
like image 523
Aspiring Dev Avatar asked Nov 06 '22 13:11

Aspiring Dev


1 Answers

It seems that the solution is to add the --exitcrash flag. It's working for me (at least when I initially tested it just now). So:

"scripts": {
  "start": "node app",
  "debug": "nodemon --experimental-modules --inspect --exitcrash ./bin/www.mjs"
}

Or alternatively:

 "runtimeArgs": [
   "run-script",
   "debug",
   "--exitcrash"
 ],

I got this idea from here: https://github.com/microsoft/vscode/issues/56756#issuecomment-462585020

like image 97
Matt Browne Avatar answered Nov 14 '22 21:11

Matt Browne