Use the Chromium inspector
This solution works with most recent Node.js versions (the other answer depends on node-inspector, which is no longer maintained and does not work with Node.js 7 or higher.
It also doesn't require running the process with --inspect
or doing any other preparation. You can use it right now with you process currently running in production.
Start by sending a signal to the process to enable debug mode:
kill -USR1 <pid>
Don't worry, your process won't be actually killed. After that, you should see a message similar to this in stderr:
Debugger listening on ws://127.0.0.1:9229/94b1fa2c-e478-4a76-bfb1-fc96c38d79610
For help, see: https://nodejs.org/en/docs/inspector
Now open chrome://inspect
in a Chromium-based browser and instruct it to inspect your process by choosing it in the list that appears.
If your process is running in a remote machine, you can easily inspect it via a SSH tunnel by running this command:
ssh -C2qTnN -L 9229:localhost:9229 <remote-machine>
Replacing both occurrences of 9229
with the actual port (check the log message printed to stderr) and <remote-machine>
with the address to your remote machine.
Reference: Node.js docs