19

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?

asked May 8, 2018 at 21:32
0

5 Answers 5

29

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!

answered May 8, 2018 at 21:32
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks! Please note, you may have to first click the Configure button, and add localhost:9221 to the Target Discovery Settings.
how can i do this without SSL ?
Do you mean SSH?
I use this without SSH on a LAN with node --inspect=0.0.0.0 server.js. The configure step above is critical.
Also, there is --inspect-brk option in node command line. It will prevent script from starting , so you may start it after debugger connected
6

With Windows Client:

on remote server:

$ node --inspect server.js

On your local use Putty to create ssh tunel.

Connection -> SSh -> Tunnels

Click On Add botton:

After Add button

On session tab Click to save!

enter image description here

And Click on Open.

You can check Tunnel is open with the following command:

netstat -a -n | grep 9221

On Your local open Chrome navigate to:

chrome://inspect/#devices

answered May 10, 2018 at 21:06

2 Comments

I had to do one change: I had to specify 'local' instead of 'remote' in the PuTTy tunnerl config. Then it worked like a charm.
In my environement, Chrome would not reliably start the debugging session. So I switched to Visual Studio Code instead and the debugger opens instantly. See my answer on this page.
4

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.

answered Jun 17, 2021 at 20:40

Comments

1

With Windows Client and Visual Studio Code

Here's a variation of Peter's answer, using Visual Studio Code instead of Chrome.

  1. Apply all steps from @Peter's answer to setup port forwarding in Putty (be sure to change remote to local as pointed out in the first comment to @Peter's answer).
  2. In Visual Studio Code, add the following configuration:
{
 // Use IntelliSense to learn about possible attributes.
 // Hover to view descriptions of existing attributes.
 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
 "version": "0.2.0",
 "configurations": [
 {
 "type": "node",
 "request": "attach",
 "name": "Attach to Remote",
 "address": "127.0.0.1",
 "port": 9221,
 "localRoot": "${workspaceFolder}/npm",
 "remoteRoot": "/abs/path/npm",
 "skipFiles": [
 "<node_internals>/**"
 ]
 },
 ]
}
  1. Use inpect-brk to pause your program until the Visual Studio Code has connected to the remote host:
node --inspect-brk your-node-program.js
answered Jan 12, 2021 at 9:40

Comments

-1

You can follow the steps

1)Run the application in remote
2)Open application in chrome
3)Open Developer Tools--->Sources
4)Ctrl + p
5)Open file you want to debug there<filename.js>
6)Place debug points in your now opened file.
answered Jul 30, 2020 at 20:09

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.