[英]How to debug node.js application with Visual Studio 2013 and Node Tools NTVS
I have moved an existing node.js + express project to VS because I prefer the IDE over JetBrains for now (used VS for years, only peeked into Webstorm). 我已将一个现有的node.js + express项目移动到VS,因为我现在更喜欢IDE而不是JetBrains(多年来使用VS,只是窥视Webstorm)。
I used NTVS new project->from existing sources and all files were imported successfully. 我使用NTVS新项目 - >来自现有来源,所有文件都成功导入。
Afterwards, I opened the project settings of my project and set the node.exe arguments to bin\\www, startup file for express. 之后,我打开了项目的项目设置,并将node.exe参数设置为bin \\ www,启动文件为express。
When I press F5 (debug) I get the console.log messages I have put into the www and app.js files in the opening command prompt, and it looks like the server is running (cannot confirm, I want to debug if everything is working), but the VS debugger directly exits again, it also does not open any page in the browser I selected for debugging. 当我按F5(调试)时,我得到我在开放命令提示符下放入www和app.js文件的console.log消息,看起来服务器正在运行(无法确认,我想调试,如果一切都是工作),但VS调试器再次直接退出,它也没有打开我选择进行调试的浏览器中的任何页面。
My node app actually is a REST webservice, so I want to test different URLs with different parameters. 我的节点应用程序实际上是一个REST Web服务,所以我想用不同的参数测试不同的URL。
Also, I cannot access the app on the port I specified, though when I directly start it from node.exe I can, even though the command prompt is still open. 此外,我无法访问我指定的端口上的应用程序,虽然我可以从node.exe直接启动它,即使命令提示符仍然打开。
(I have NTVS and WebEssentials installed - some operations take a long long time, but I attribute this to NTVS being still an early version.) (我安装了NTVS和WebEssentials - 某些操作需要很长时间,但我将其归结为NTVS仍然是早期版本。)
Question: how does the Visual Studio debugger stay connected to the node.js application so I can use breakpoints and use any browser then to connect and test different URLs? 问题: Visual Studio调试器如何与node.js应用程序保持连接,以便我可以使用断点并使用任何浏览器来连接和测试不同的URL? (Even a breakpoint put on the console.log that gets printed during startup is not being triggered.) (即使是在启动期间打印的console.log上的断点也没有被触发。)
For everyone who asks receives, and the one who searches finds.... 对于要求收到的每个人,以及搜索的人发现....
(and yes, I did spend a long time searching and trying before posting here..) (是的,我确实花了很长时间搜索并尝试发布之前..)
Kind of nice to debug node.js server with VS.. 很高兴用VS调试node.js服务器..
hope this helps someone 希望这有助于某人
Edit: The arguments to node.exe can be hard to read in the image. 编辑:可能难以在图像中读取node.exe的参数。 It must be 肯定是
--debug=<portno>
that is with two dashes (and not just one) to specify the debug port. 用两个短划线(而不仅仅是一个)来指定调试端口。
Not so much knowledge on expressjs
but with a recent release of NTVS
1.0 Alpha, I did find it supports remote debugging which can be also used to debug nodejs
app running locally - anyway haven't tried if it works with nodejs app + expressjs but it should. 在没有这么多的知识expressjs
但最近释放NTVS
1.0阿尔法,我没发现它支持远程调试这也可以用来调试nodejs
应用程序在本地运行-无论如何,如果它与应用程序的NodeJS + expressjs但它的作品没有试过应该。
I followed the step in this video https://youtu.be/-ir9ZB8lUg4 which is 我按照这个视频中的步骤https://youtu.be/-ir9ZB8lUg4这是
node.exe RemoteDebug.js <your_javascript_file>
. 使用node.exe RemoteDebug.js <your_javascript_file>
运行node.exe RemoteDebug.js <your_javascript_file>
。 RemoteDebug.js
has come when you install NTVS. 安装NTVS时出现RemoteDebug.js
。 Debug
> Attach to Process
在Visual Studio中,选择“ Debug
>“ Attach to Process
Node.js remote debugging
for Transport 为Transport选择Node.js remote debugging
localhost:5859
for Qualifier 输入localhost:5859
作为限定符 Attach
单击Attach
This will put Visual Studio in debugging mode which you can set a breakpoint, do step-in/step-out, very same experience when you use VS to debug .NET app. 这将使Visual Studio处于调试模式,您可以设置断点,执行步进/跳出,使用VS调试.NET应用程序时的体验非常相同。
Its pretty straight forward with NTVS , you can download required version for your windows from github here 它非常简单的NTVS ,您可以从github下载所需的Windows版本
Once you install NTVS, NodeJS project templates will be added 安装NTVS后,将添加NodeJS项目模板
Now, Goto File->New project -> Basic NodeJS Express 3 application ( it will be available in javascript project templates ) 现在,转到文件 - >新项目 - >基本NodeJS Express 3应用程序( 它将在javascript项目模板中提供 )
Now just goto debug and select Start Debugging , add breakpoints where ever required and you can start debugging 现在只需转到debug并选择Start Debugging ,在需要的地方添加断点,然后就可以开始调试了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.