如何设置nodejs调试模式不要监听127.0.0.1

时间:2012-01-20 08:49:04

标签: eclipse node.js remote-debugging google-chrome-devtools

我想在Eclipse中远程调试nodejs程序。我使用debug选项启动节点脚本。

$node debug script.js

但我无法连接到Eclispe中的节点。当我netstat节点的TCP端口。我发现节点只在调试模式下监听127.0.0.1。所以我无法从不同的电脑连接它。

但我找不到任何可以改变以听取任何地址的启动选项。

有人知道让它听任何地址到其他计算机远程调试吗?

5 个答案:

答案 0 :(得分:4)

我正在查看通过deps / v8 / src / debug-agent。*到deps / v8 / src / platform-posix.cpp(对于linux)到POSIXSocket :: Bind方法的V8代码,它可以似乎对此有任何选择(除非我遗漏了什么)。

我敢打赌你要么破解它并重新编译节点,要么你需要在节点进程旁边构建一个小代理。

答案 1 :(得分:4)

这就是我在linux Debian中所做的:

安装平衡器

sudo apt-get install balance -y

然后在平衡器中创建一条路线,将您的5858端口重新路由到5859

balance 5859 127.0.0.1:5858

启动你的应用

node --debug app.js

现在您可以从端口5859上的任何位置访问它

答案 2 :(得分:3)

如果有其他人偶然发现这一点:您可以在设置端口时将节点调试设置为任何地址

node --debug=169.168.1.2:5858 app.js

如果那是你的远程机器的ip,或者甚至更好的是每台机器

node --debug=0.0.0.0:5858 app.js

但请注意,只有当您在自己的私人网络中进行调试时,才应使用第二个选项

答案 3 :(得分:2)

Here's a great tut on debugging nodejs from eclipse。请注意,底部有一个脚本,作者使用该脚本将localhost:5858转发到远程服务器的127.0.0.1。你也可以use an SSH tunnel

所以,总结一下:

  1. 使用node --debug app.js
  2. 启动您的脚本
  3. 配置eclipse就像在本地调试一样
  4. 使用node_g脚本或配置SSH隧道
  5. 现在你的代码没有错误,
  6. 去度假

答案 4 :(得分:0)

要通过SSH会话远程调试nodejs,请执行以下操作:

1. install balance on Linux: https://balance.inlab.net/overview/
2. run the command: balance -df 8585 127.0.0.1:5858 > /tmp/balance.out 2>&1 &
3. ssh to your remote Linux box (tunnel will be created 8585 > 5858 > nodejs)
4. run your node script on server: node --debug-brk --nolazy ./myNodeApp.js
5. kick off debug session in WebStorm alt-d to port 8585

现在您正在通过SSH会话安全地进行远程调试