Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nodemon development setup by adding support to automatically re-attach when node is restarted #3238

Closed
3 tasks done
joaomoreno opened this issue Feb 22, 2016 · 7 comments
Assignees
Milestone

Comments

@joaomoreno
Copy link
Member

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:

  • 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.
@ronjouch
Copy link

ronjouch commented Jan 27, 2017

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.

@ianfiske
Copy link

ianfiske commented May 5, 2017

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

@weinand
Copy link
Contributor

weinand commented May 5, 2017

@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"...

@ianfiske
Copy link

ianfiske commented May 5, 2017

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!

@weinand
Copy link
Contributor

weinand commented May 5, 2017

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).

@cvharris
Copy link

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.

@weinand
Copy link
Contributor

weinand commented May 11, 2017

@cvharris you are missing a "restart": "true" attribute.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants