如何debugging一个运行在Chrome / WebKit上的Node.js服务器作为远程debugging器?

如果你有你的节点运行

node --debug server.js 

这给了我一个端口号xxxx,我应该在启动Chrome时使用这个端口号吗?

你是否从Google\ Chrome --remote-debugging-port=xxxx远程debugging到它 – Google\ Chrome --remote-debugging-port=xxxx

或者是9222是一个魔术端口,因为它被提到全部。

我在正确的轨道上,试图用--remote-debugger启动Chrome到Node.js server.js

节点检查员/ – debugging器现在被检查员replace见下面的更新

 #now deprecated / see below for update #install node-inspector npm install -g node-inspector #start node-inspector, listen on port 8080 (default) node-inspector --web-port=8080 #in another terminal session/window: #while node-inspector is running, start your project in debug mode node --debug myproject.js 

现在,您可以浏览到http:// your_server:8080,查看myproject.js的完整debugging会话

如果远程服务器由于防火墙或其他原因无法在远程端口上访问,则可以从本地计算机上的端口8080到远程服务器上的“localhost:8080”创build一个ssh-tunnel:

 ssh -L 8080:localhost:8080 username@remoteserver -N 

并在本地机器上使用http:// localhost:8080的同时继续运行,以debugging远程nodejs会话


更新2017年8月

在检查模式下启动节点:

 node --inspect=0.0.0.0:9229 myproject.js 

或者如果您希望debugging器在myproject.js的第一行中断:

 node --inspect-brk=0.0.0.0:9229 myproject.js 

然后在Chrome浏览器中打开以下URL:

 chrome://inspect 

点击“configuration…”button并添加以下目标:

 ip-or-name-of-server-running-node:9229 

点击“完成”button后,您应该在远程目标下看到myproject.js。 点击检查链接开始debugging。 不幸的是,检查链接不适用于Ubuntu的Chrome 58。 它适用于Windows的Chrome 60。

使用node-inspector从Chrome浏览器远程debugging您已经使用--debug选项开始的节点应用程序,如您所示。

Node(> v6.3.0)和Chrome的最新版本现在允许您使用Chrome开发人员工具来debuggingNode.JS进程,而无需另外安装任何其他程序。 只要通过 – --inspect node

 $ node --inspect script.js Debugger listening on port 9229. Warning: This is an experimental feature and could change at any time. To start debugging, open the following URL in Chrome: chrome-devtools://SOME-URL-HERE 

只需在Chrome中打开该url,即可开始使用。

如果您需要在节点启动后立即暂停脚本,则还可以在同一命令中传递--debug-brk

  • 使用$ vagrant ssh – -L 5858:127.0.0.1:5858

      to ssh connect to VM. also this comment would start a proxy server on port 5858; 
  • 您可以使用telnet 127.0.0.1 5858testing本地代理服务器是否启动。

  • 在VM中,您可以使用命令启动节点

  • $ node –debug-brk app.js

  • 在web风暴中设置debuggingconfiguration。
  • 当您在Web风暴中启动debugging时,VM中的node.js服务器将在几秒钟内启动。

PS:没有必要去碰stream浪文件。 参考: 将WebStorm连接到远程的node.jsdebugging会话 。