Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js: how to debug remotely?

I have a Linux server (os: Centos, ip: 192.168.1.100) with my node app that I want to debug.
For some reason @office I have to work on a remote client (ip: 192.168.1.7), since Linux server has no GUI/browser.

I did follow the instruction to use node-inspector, without success...

Here is what I did:

$ npm --version
2.14.2

$ node --version
v4.0.0

$ npm install -g node-inspector

$ node-inspector --version
Node Inspector v0.12.3

$ node-debug myApp.js
Node Inspector is now available from http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858
Debugging `myApp.js`

Debugger listening on port 5858

Then if I open my client browser to http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858 , I get error ERR_ADDRESS_UNREACHABLE.

The same result if I open my client browser to http://192.168.1.100:8080/?ws=192.168.1.100:8080&port=5858.

If (out of curiosity) I open http://192.168.1.100:5858 I just get:

Type: connect
V8-Version: 4.5.103.30
Protocol-Version: 1
Embedding-Host: node v4.0.0
Content-Length: 0

I did already open port 8080 and 5858 (to be on the safe side) on my firewall (in /etc/sysconfig/iptables I have:

...
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 5858 -j ACCEPT
...

).

What do I miss?


UPDATE: After @aleung suggestion, I did add web-host=0.0.0.0 flag to node-debug command line, without great success: I always get ERR_ADDRESS_UNREACHABLE in browser. Even a telnet 192.168.1.100 8080 from the 192.168.1.7 client times-out. Instead, a telnet 192.168.1.100 5858 answers:

Type: connect
V8-Version: 4.5.103.30
Protocol-Version: 1
Embedding-Host: node v4.0.0
Content-Length: 0

Which probably means debugger is listening, but it's still unreachable from the client interface :-(

like image 833
MarcoS Avatar asked Dec 14 '15 14:12

MarcoS


People also ask

Does node JS provide any debugger?

Node. js includes a command-line debugging utility. The Node. js debugger client is not a full-featured debugger, but simple stepping and inspection are possible.

How do I inspect node js in Chrome?

To inspect your Node. js app with Google Chrome DevTools, you have to make it a remote target. This can be done by using the --inspect flag when starting the node process: node --inspect ./dist/app.

Is a GUI based debugging tool for Node JS?

Node Inspector is a GUI-based debugging tool for Node. js.


1 Answers

By default node-inspector web server listens on 127.0.0.1, only accept connection from localhost. You have to start node-inspector on your server with option --web-host=0.0.0.0

$ node-debug --web-host 0.0.0.0 myApp.js

Then open your client browser to http://server:8080/?ws=server:8080&port=5858, where server is your server IP.

like image 130
aleung Avatar answered Oct 15 '22 03:10

aleung