There are 3 steps involved:
Connect to the remote machine, get the pid of the Node.js process and then run:
kill -usr1 <pid>
This will signal the Node.js process that it should turn into debug mode. Port 9229 should be open now.
On your local machine:
ssh -C2qTnN -L 9229:localhost:9229 <remote-machine>
Where <remote-machine>
is the host where the Node.js process is running. It should be configured in your ~/.ssh/config
file. This will open local port 9229, tunnelling it to remote por 9229 (the port where the debug server is listening).
After step 2, you can act as if the remote process' debug server is running on your local machine. Just use any tool you'd use to debug local processes.
To use Chrome, go to chrome://inspect
. Your remote process should appear there. It still don't know how to navigate through the sources and add breakpoints, but I used it to take heap snapshots and it was very useful.
Create a new Attach to Node.js/Chrome
run configuration. Confirm it is set to connect to por 9229 and run it. Considering you have your project opened, you should now be able to add breakpoints to any part of the code.