Vscode: Support `nodemon` development setup by adding support to automatically re-attach when node is restarted

Created on 22 Feb 2016  路  7Comments  路  Source: microsoft/vscode

Issue: #2103
Assignees:

  • [x] Windows @joaomoreno
  • [x] OS X @isidorn
  • [x] Linux @aeschli

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:

  • on the command line start your node (server) program like this:
nodemon --debug server.js
  • in VS Code create this attach launch config:
{
    "name": "Attach",
    "type": "node",
    "request": "attach",
    "port": 5858,
    "restart": true
}
  • Now 'Attach' in VS Code.

Test:

  • Verify that VS Code always restarts the debug session successfully after nodemon has restarted node.
  • Test the behaviour if the session is stopped in VS Code or nodemon is killed.
testplan-item

Most helpful comment

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.

All 7 comments

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.

Was this page helpful?
0 / 5 - 0 ratings