Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to debug a currently running production Node application?

Locally I debug by running node --debug and using the node-inspector tool. node-inspector must be running in the background, then I point my browser (not all browsers work; Chrome does) to http://127.0.0.1:8080/debug?port=5858 to debug.

Problem is I can't run a production server locally (missing private key files that don't belong on a dev machine), making it very hard to debug certain production problems, even if I'm willing to hack on a production machine. Is this still possible with Node inspector?

like image 577
djechlin Avatar asked Aug 23 '13 00:08

djechlin


People also ask

Can I debug Node js?

In a similar way to auto attach, the JavaScript Debug Terminal will automatically debug any Node. js process you run in it. You can create a Debug Terminal by running the Debug: Create JavaScript Debug Terminal command from the Command Palette ( kbs(workbench.

Which tools can be used to debug Node js application?

The V8 inspector integration allows attaching Chrome DevTools to Node. js instances for debugging by using the Chrome Debugging Protocol. In most cases, it makes sense to stop the execution of the application at the very first line of your codebase and continue the execution from that.

Which CLI option can you use to debug a node?

A minimal CLI debugger is available with node inspect myscript. js . Several commercial and open source tools can also connect to the Node. js Inspector.


1 Answers

Yes, you just need to follow a few steps from node inspector's README:

  1. node-inspector has to be running on the machine with the node process you are trying to debug. So, you must be able to install this there.
  2. Presumably your production process did not start with the --debug flag. You can send a signal to achieve this though: kill -s USR1 <pid>. (pid can be obtained with something like ps aux | grep node.)
  3. Make sure port 8080 is exposed to your local machine from your production machine.
  4. Point your browser as normal; you're all set up.
like image 155
djechlin Avatar answered Sep 30 '22 19:09

djechlin