Issue: #2103
Assignees:
Setting the new launch config attribute restart to true makes node-debug to automatically restart the session if the debug target has terminated. This is useful if you use nodemon to restart node on file changes.
Setup:
nodemon --debug server.js
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"restart": true
}
Test:
In case it helps someone, chiming in that this support for nodemon works too with the (currently experimental) node2 debug type (V8 Inspector Protocol). Just ~change type to node2 and port to 9229, and run nodemon with --inspect instead of --debug~ EDIT as mentioned below, new correct way is just "type": "node", "protocol": "inspector" :) , attaching works and reloading on change works.
Just a small update @ronjouch for using the inspector protocol. Using node 6.10.2 and nodemon 1.11.0 with vscode 1.12.1, set type to node and protocol to inspector
"type": "node",
"runtimeArgs": [
"--inspect"
],
"protocol": "inspector",
"port": 9229
@ianfiske the "runtimeArgs": [ "--inspect" ] and "port": 9229 is not needed because "protocol": "inspector" does exactly that (and more).
I even recommend against this redundancy because you can easily create an inconsistency if you keep "runtimeArgs": [ "--inspect" ] and change "protocol" to "legacy"...
Ah, thank you @weinand. If I remove only the runtimeArgs it fails (hence my mistake earlier that it was needed). But if I remove both runtimeArgs and port like you suggested, then it works!
Yes, if you set a port, we take this as an indication that you want to control everything yourself. In this case you have to specify the --inspect or --debug flag.
If no port is given, we pick a random free port and pass it to the runtime either as --debug=12345 or --inspect=12345 (depending on the value of protocol).
This doesn't seem to be working still. Here's my launch.json:
{
"type": "node",
"request": "attach",
"name": "Attach (Inspector Protocol)",
"port": 9229,
"protocol": "inspector"
}
When I run nodemon --inspect index.js the debugger attaches but on restart of the server it detaches and I have to start the VSCode debugger all over again.
@cvharris you are missing a "restart": "true" attribute.
Most helpful comment
In case it helps someone, chiming in that this support for nodemon works too with the (currently experimental)
node2debug type (V8 Inspector Protocol). Just ~changetypetonode2andportto9229, and run nodemon with--inspectinstead of--debug~ EDIT as mentioned below, new correct way is just"type": "node", "protocol": "inspector":) , attaching works and reloading on change works.