如何在Windows上调试基本的node.js应用程序(而非http) [英] How to debug a basic node.js application (not http) on windows

查看:155
本文介绍了如何在Windows上调试基本的node.js应用程序(而非http)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用node-inspector和iisnode调试http应用程序.但是我可以在Windows上使用node-inspector调试 non http 节点应用程序吗?

I know how to debug http applications using node-inspector and iisnode. But can I use node-inspector to debug a non http node application, on windows?

我尝试过:

 node debug test.js

它说:

debugger listening on port 5858

但是在Chrome中打开http://localhost:5858/不会执行任何操作.

But opening http://localhost:5858/ in Chrome does not do anything.

BTW:运行node debug test.js确实会启动有效的命令行调试器.但这不像节点检查器.

BTW: running node debug test.js does start the command-line debugger which works. But it's nothing like node-inspector.

推荐答案

要使用node-inspector,正确的开关是node --debug而不是node debug

To use node-inspector, the right switch is node --debug not node debug

以下是详细步骤:

  1. 全局安装节点检查器(npm install -g node-inspector)
  2. 在命令行窗口中,运行:node-inspector
  3. 打开Chrome并转到http://localhost:8080/debug?port=5858.您将获得节点检查器用户界面,但没有任何正在运行的应用程序.
  4. 在另一个命令行窗口中,使用--debug开关运行您的应用,如下所示:node --debug test.js
  5. 刷新Chrome标签并瞧!
  1. install node-inspector globally (npm install -g node-inspector)
  2. from a command-line window, run: node-inspector
  3. open Chrome and go to http://localhost:8080/debug?port=5858. You'll get the node-inspector UI but without any running app.
  4. from another command-line window, run your app with the --debug switch like this: node --debug test.js
  5. refresh the Chrome tab and voila!

一些有趣的观点:

  • 如果您终止应用程序并重新启动,则只需刷新node-inspector选项卡即可.它将保留您所有的断点.
  • 要在第一行自动中断,请使用node --debug-brk test.js
  • 启动您的应用
  • If you kill your app and start it again, just refresh the node-inspector tab. It will keep all your breakpoints.
  • To break automatically on the first line start your app with node --debug-brk test.js

这篇关于如何在Windows上调试基本的node.js应用程序(而非http)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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