我使用
- 快递:4.13.4
- 吞咽:3.9.1
- mongodb :v3.0.6
- reactjs:15.0.2.
- 节点:4.0.0
对于服务器端代码,我听说可以通过 Visual Studio Code (v1.1.1.) 进行调试.
For server side code i hear it is possible to debug via Visual Studio Code (v1.1.1.).
从 git bash 我通过 gulp serve 启动应用程序.但是我不知道如何开始调试!
From git bash i start the app via gulp serve.But i am at a loss to find out how to Start debugging!
我的 gulp 任务的片段.
A snippet of my gulp task.
gulp.task('serve',['bundle','start-server'],function(){ browserSync.init({ proxy:'localhost:3000', port:9001 }); });当我们点击 VS Code 上的调试按钮启动调试界面时,我们会看到一个 launch.json ,其中我们有两个配置选项.
When we click the debug button on VS Code to launch the debug interface, we r presented with a launch.json , where we have two configuration options.
{ "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "node", "request": "launch", "program": "${workspaceRoot}", "stopOnEntry": false, "args": [], "cwd": "${workspaceRoot}", "preLaunchTask": null, "runtimeExecutable": null, "runtimeArgs": [ "--nolazy" ], "env": { "NODE_ENV": "development" }, "externalConsole": false, "sourceMaps": false, "outDir": null }, { "name": "Attach", "type": "node", "request": "attach", "port": 3000, "address": "localhost", "restart": false, "sourceMaps": false, "outDir": null, "localRoot": "${workspaceRoot}", "remoteRoot": null } ]}
我猜这些是 launch 和 attach 配置.但是我们实际上如何通过调试启动 gulp.
i am guessing these are launch and attach configs. But how do we actually lauch gulp via debug.
我见过人们通过将program"键修改为program":/usr/local/bin/grunt"来启动grunt进程.但似乎我无法为 gulp 做到这一点
i have seen people launch grunt process by modifying the "program" key as "program": "/usr/local/bin/grunt". But it seems i am not able to do that for gulp
即使我通过 git bash 启动了我的应用程序并尝试按照提到的附加"调试器 这里,vs代码只显示一条错误消息,说已取消"!
Even when i have launched my app via git bash and try to 'attach' the debugger as mentioned here , vs code just shows an error message saying 'Cancelled' !
TLDR;
- 当我们在 VS 代码中启动调试时,我们如何启动 gulp(或)grunt(或)启动服务器?
- 是否可以通过 cmd 或 bash 从外部启动应用程序,并且仍然能够使用调试器调试服务器端代码?如果是这样,launch.json 中需要进行哪些更改?
好吧,后来我终于通过launch和attach成功调试了很多书签和链接.
Allrighty, numerous bookmarks and links later i have finally succeeded in debugging via launch and attach.
通过 launch 配置调试:
Debug via launch config:
{ "name": "Launch", "type": "node", "request": "launch", "program": "${workspaceRoot}/server.js", "stopOnEntry": true, "args": [], "cwd": "${workspaceRoot}", "preLaunchTask": null, "runtimeExecutable": null, "runtimeArgs": [ "--nolazy" ], "env": { "NODE_ENV": "development" }, "externalConsole": false, "sourceMaps": false, "outDir": null }在 VSC 调试视图中按下绿色 > 按钮并在下拉菜单中选择启动选项,您应该会在 VSC 控制台中看到类似的内容.
on pressing the green > button on the VSC debug view with launch option selected in the dropdown, you should see something like this in the VSC console.
node --debug-brk=21735 --nolazy server.js调试器应该在 server.js 文件的第一行暂停.用断点调试!:)
And a the debugger should pause on the first line of your server.js file. Debug away with breakpoints ! :)
通过 attach 配置调试:
Debug via attach config:
{ "name": "Attach", "type": "node", "request": "attach", "port": 5858, "address": "localhost", "restart": false, "sourceMaps": false, "outDir": null, "localRoot": "${workspaceRoot}", "remoteRoot": null }从外部启动你的服务器
$node --debug-brk server.js你的提示应该暂停在
Debugger listening on port 5858按下 VSC 调试视图上的绿色 > 按钮,并在下拉列表中选择附加选项,调试器应自动附加自身并在 server.js 的第一行暂停
Press the green > button on the VSC debug view with attach option selected in the dropdown , the debugger should automatically attach itself and pause at the first line of server.js
调试广告恶心
更多推荐
使用 Visual Studio Code 调试 ExpressJS 服务器端代码
发布评论