Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Debugging remote Node.js processes

Debugging remote Node.js processes

There are 3 steps involved:

1. send a signal to the process so it enters debug mode

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.

2. use port forwarding to connect to remote process

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

3. debug using your local tools

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.

3.1 Chrome

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.

3.2 Webstorm

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.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment