Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug remote node.js app using chrome devtools

I have a simple console node.js app that is running on a remote server. I would like to debug it remotely using the Chrome DevTools. How can I do that?

like image 746
jramirez Avatar asked May 08 '18 21:05

jramirez


Video Answer


2 Answers

There are security considerations, but the following can be an easy/safe solution if on the same network:

On server, launch your app:

node --inspect=0.0.0.0:9229 server.js

Rather than having node bind strictly to localhost, you can have it bind to any network interface via 0.0.0.0:9229.

Now on your PC, open chrome and goto chrome://inspect/#devices . Chrome has changed the UI accouple times but you should be able to configure your remote server IP as a target. E.g. [server_ip]:9229. Note, this would be safest to use on a local network where server_ip is a local IP address. If you are debugging against a public IP address there would be a risk of someone else attaching.

like image 86
user6933749 Avatar answered Oct 13 '22 03:10

user6933749


Follow this instruction here Another good article here

Let's say you are running Node on remote machine, remote.example.com, that you want to be able to debug. On that machine, you should start the node process with the inspector listening only to localhost (the default).

$ node --inspect server.js

Now, on your local machine from where you want to initiate a debug client connection, you can setup an ssh tunnel:

$ ssh -L 9221:localhost:9229 [email protected]

Then on your local machine in the Chrome browser go to this address:

chrome://inspect/#devices

You should see something like this:

enter image description here

Once you click inspect you should see the familiar Chrome developers tool window. Good luck!

like image 22
jramirez Avatar answered Oct 13 '22 02:10

jramirez