如何调试使用Chrome / WebKit作为远程调试器运行的Node.js服务器? [英] How do you debug a Node.js server running with Chrome/WebKit as the remote debugger?

查看:75
本文介绍了如何调试使用Chrome / WebKit作为远程调试器运行的Node.js服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您的Node正在运行

  node --debug server.js 



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



您是否通过 Google \ Chrome --remote-debugging-port = xxxx



或者是9222是一个魔术端口,因为它已经被提及。



我在正确的轨道上试图用来启动Chrome吗? -remote-debugger 添加到Node.js中 server.js

解决方案

p> #现在不推荐使用/请参阅下面的更新

#install node-inspector
npm install -g节点检查器

#start节点检查器,监听端口8080(默认)
node-inspector --web-port = 8080

#在另一个终端会话/窗口中:
#while节点检查器是r unning,以调试模式启动你的项目
node --debug myproject.js

现在你可以浏览 http:// your_server:8080 获取myproject.js的完整调试会话。



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

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

并使用 http:// localhost: 8080 在您的本地机器上调试远程nodejs会话




更新2017年8月



以检查模式启动节点:

  node --inspect = 0.0.0.0:9229 myproject.js 

或者如果您想要调试器在myproject.js的第一行中断:

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

然后在您的Chrome浏览器中打开以下网址:

  chrome://检查

'Configure ...'按钮并添加以下目标:

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

当您点击'完成'按钮后,您应该会看到myproject.js在您的远程目标。点击检查链接开始调试。不幸的是,检查链接不适用于Ubuntu的Chrome 58。它适用于Windows的Chrome 60。


If you have your Node running

node --debug server.js

This gives me a port number xxxx, should I use this port number when starting Chrome?

Do you remote debug into it from Google\ Chrome --remote-debugging-port=xxxx?

Or is the 9222 a magic port, as it is mentioned all over.

Am I on the right track, trying to start Chrome with --remote-debugger into the Node.js server.js

解决方案

The node-inspector / --debug are now replaced by inspector See update below

#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

Now you can browse to http://your_server:8080 for a full debug session of myproject.js

If your remote server is not accessible on the remote port because of firewalls or other reasons, you could create an ssh-tunnel to it from port 8080 on your local machine to 'localhost:8080' on the remote server:

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

and keep this running while you use http://localhost:8080 on your local machine to debug your remote nodejs session


Update august 2017

Start node in inspect mode:

node --inspect=0.0.0.0:9229 myproject.js

or if you want the debugger to break at the first line of myproject.js:

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

Then open the following URL in your chrome browser:

chrome://inspect

Click the 'Configure...' button and add the following target:

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

After you click the 'Done' button, you should see myproject.js under your remote targets. Click the inspect link to start debugging. Unfortunately, the inspect link does not work on Chrome 58 for Ubuntu. It works fine on Chrome 60 for Windows.

这篇关于如何调试使用Chrome / WebKit作为远程调试器运行的Node.js服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆