Skip to content

Instantly share code, notes, and snippets.

@tomi
Last active January 13, 2020 07:50
Show Gist options
  • Save tomi/e4674a12fc47c62fc19bcb879b4c92c6 to your computer and use it in GitHub Desktop.
Save tomi/e4674a12fc47c62fc19bcb879b4c92c6 to your computer and use it in GitHub Desktop.
How to debug a node process running in VM with VS Code
  1. Launch the node process in the VM with --debug-brk flag. This will break the execution of the node process in the start. node --debug-brk <app.js> <args>. Node.js versions >= 6.3 support new inspector protocol: node --inspect <app.js> <args>

  2. Create a launch config in VS Code with a mapping from the VM file system to the local file system

{
  "name": "Attach node",
  "type": "node",
  "request": "attach",
  "address": "localhost",
  "port": 5858,
  "localRoot": "<cwd path in local file system>",
  "remoteRoot": "<cwd path in VM file system>"
}

Or with new inspector protocol:

{
  "name": "Attach node",
  "type": "node",
  "request": "attach",
  "address": "localhost",
  "port": 9229,
  "protocol": "inspector",
  "localRoot": "<cwd path in local file system>",
  "remoteRoot": "<cwd path in VM file system>"
}
  1. Attach to the running node process using the launch config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment