简体   繁体   中英

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 :-(

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.

node 7.x

node --inspect :file_name

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM