VS Code Debugger does not kill node process after stopping the debugger

Viewed 2216

I am working on a node.js application using express.js as a web framework listening on PORT 3000. I am using VS Code v1.46.

My launch.json file is

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "program": "${workspaceFolder}\\WebApi\\index.js",
        "restart": true,
        "protocol": "inspector"
    }
   ]
  }

I am able to start the debugging session for the first time, but 2nd time onwards, I get error Error: listen EADDRINUSE: address already in use :::3000

This error is because VSCode didn't terminate the node.exe process created in 1st debugging session and so in the subsequent session node failed to start the express server on port 3000 as it is still in used.

Can anyone help me to configure VSCode to terminate node.exe process once I stop the debugger?

2 Answers

This issue started just last week for me, not sure why, maybe windows update.

Any way I found the following : https://github.com/OmniSharp/omnisharp-vscode/issues/2387

where they say that if you add to lunch.json "console": "externalTerminal" or "console": 'integratedTerminal'

it will open a console for the process so that u can kill manually

It works fine with the Using the "preview" debug extension.

This is the launch.json for using that mode, just make sure that you put the correct command of your package.json.

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node-terminal",
      "name": "Run Script: start",
      "request": "launch",
      "command": "npm run start",
      "cwd": "${workspaceFolder}"
    }
  ]
}
Related