简体   繁体   English

使用Visual Studio Code调试节点js

[英]Debug node js with Visual Studio Code

I try to debug a Project in node JS with Visual Studio Code but i don't achieve. 我尝试使用Visual Studio Code在节点JS中调试项目,但我没有实现。 I have built a simple project with the next commands: 我用下一个命令构建了一个简单的项目:

express myExpressApp 表达myExpressApp
cd myExpressApp cd myExpressApp
npm install npm安装
npm start npm开始

My file launch.json: 我的文件launch.json:

在此输入图像描述

I select the Option “Launch app.js” in Window “Debug”. 我在Window“Debug”中选择选项“Launch app.js”。 The application run without problems. 应用程序运行没有问题。 I put a breakpoint: 我提出了一个断点:

在此输入图像描述

I give in Chrome the address: http://localhost:3000/ 我在Chrome中给出了地址: http:// localhost:3000 /

Visual Studio Code says: “Pause on breakpoint”, but I don't see anything, I can press Continue and the application continues... Visual Studio Code说:“在断点暂停”,但我没有看到任何内容,我可以按继续,应用程序继续...

暂停断点

Edited: I use OS X 10.10 (I tested it and it works perfectly in Ubuntu.) 编辑:我使用OS X 10.10(我测试了它,它在Ubuntu中完美运行。)

VSCode 0.8.0 has problems with node versions older than 0.12.0. VSCode 0.8.0存在早于0.12.0的节点版本的问题。 Upgrade to at least 0.12.0 or wait for the upcoming VSCode 0.9.0. 升级到至少0.12.0或等待即将推出的VSCode 0.9.0。

When debugging with Visual Studio Code, there are many things you can do when you hit a breakpoint. 使用Visual Studio Code进行调试时,遇到断点时可以执行许多操作。

In order to go to the "debugging" view, you can either click the "bug" icon on the left or hit Ctrl + Shift + D . 要进入“调试”视图,您可以单击左侧的“错误”图标或Ctrl + Shift + D

You see Paused on breakpoint. 你看到Paused on breakpoint. in the Call Stack window. 在“ 调用堆栈”窗口中。 That window includes the callstack and you can double-click the different frames to navigate through the corresponding source. 该窗口包含callstack,您可以双击不同的帧以浏览相应的源。

You can also see the Variables window here to see the values of the variables (local/global/closure/etc.). 您还可以在此处看到“ 变量”窗口以查看变量的值(local / global / closure / etc.)。

One of the more used functionality parts of debugging in VS Code is the debug console. VS Code中调试中较常用的功能部分之一是调试控制台。 In the debugging view, there's a little icon right next to the configuration that you're using that looks like the CLI character. 在调试视图中,您正在使用的配置旁边有一个小图标,看起来像CLI字符。 You can either click that or just do a command palette search ( Ctrl + Shift + P ) for Debug: open Console . 您可以单击该命令,也可以只执行命令选项板搜索( Ctrl + Shift + P )进行Debug: open Console This will bring up the debugging console for your ad hoc debugging commands. 这将打开您的临时调试命令的调试控制台。

The documentation on VS Code debugging is quite robust, too, so I recommend you take a look at this . 关于VS Code调试的文档也非常强大,所以我建议你看看这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM