VSCode will start a new process to debug Node.js
- Run Node.js manually, use websocket to listen to debug info
- Start a process attach to websocket port
node --inspect-brk index.js
- Open Chrome, go to
chrome://inspect
- Start debugging!
node --inspect-brk server.js
- Open Chrome, go to
chrome://inspect
- Let go of first breakpoint
- Add breakpoint
- Visit
localhost:3000
, start debugging
Create .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch",
"program": "${workspaceRoot}/index.js"
},
{
"type": "node",
"request": "attach",
"name": "Attach",
"port": 9229
},
{
"name": "Attach to nodemon",
"type": "node",
"request": "attach",
"restart": true,
"port": 9229
}
]
}
- Go to Run Extension
- Launch Node.js
- Start debugging
node --inspect-brk server.js
- Go to Run Extension, start attach process
- Let go of first breakpoint
- Add breakpoint
- Visit
localhost:3000
, start debugging
nodemon --inspect-brk server.js
- Almost the same as above, apart from starting the
Attach to nodemon