Node.js 如何使用VSCode和grunt contrib connect连接到节点
我无法使用Visual Studio代码调试节点应用程序 我的Node.js 如何使用VSCode和grunt contrib connect连接到节点,node.js,visual-studio-code,grunt-contrib-connect,Node.js,Visual Studio Code,Grunt Contrib Connect,我无法使用Visual Studio代码调试节点应用程序 我的.vscode/launch.json如下所示: { "version": "0.2.0", "configurations": [{ "name": "Attach", "type": "node", "request": "attach", "port": 9001 }] } connect: { server: { options: { debug:true,
.vscode/launch.json
如下所示:
{
"version": "0.2.0",
"configurations": [{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 9001
}]
}
connect: {
server: {
options: {
debug:true,
port: 9001,
base: '.',
livereload: true,
},
},
},
我用它来启动我的网络服务器。我的连接任务定义为Mygrunfile.js
,如下所示:
{
"version": "0.2.0",
"configurations": [{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 9001
}]
}
connect: {
server: {
options: {
debug:true,
port: 9001,
base: '.',
livereload: true,
},
},
},
在使用上述任务成功启动web服务器后,我尝试从VSCode附加,但除了一些UI闪烁之外,似乎什么都没有发生。未命中断点
我阅读了,特别是将VS代码附加到节点部分,这就是为什么我在连接任务中添加了debug:true
。但是,这似乎没有解决任何问题。如果我正确理解grunt-contrib.connect中的“端口”,则这是Web服务器将响应的端口,而不是调试端口
因此,在.vscode/launch.json中,必须指定调试端口,而不是Web服务器端口。由于grunt使用node,我假设调试端口是node的默认端口5858。这似乎让我更进一步。然而,VS代码现在无法附加:“无法连接到运行时进程(5000ms后超时)”我认为“debug:true”做的事情不对。grunt contrib connect文档说:“将debug选项设置为true以启用日志记录,而不是使用--debug标志。”这听起来不像是节点调试。我从未使用过grunt,但很可能您必须在调试模式下启动grunt,如:“node--debug brk$(哪个grunt)”.Hmm。这允许我使用VS代码来调试grunt本身,而不是我的网站。我建议您尝试了解如何调试基于grunt的Web服务器。我熟悉VS代码(因为我是开发人员),我知道如何配置VS代码,但我不知道如何配置grunt来调试Web服务器。。。