如何使用VSCode和grunt-contrib-connect连接到节点

时间:2015-12-02 18:58:52

标签: 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
  }]
}

我使用grunt-contrib-connect启动我的网络服务器。我的连接任务定义为我的gruntfile.js,如下所示:

connect: {
  server: {
    options: {
      debug:true,
      port: 9001,
      base: '.',
      livereload: true,            
    },
  },
},

使用上述任务成功启动Web服务器后,我尝试从VSCode附加,但除了一些UI闪存之外,似乎没有任何事情发生。没有破坏点。

我阅读了VS Code Debugging Documentation,特别是将VS代码附加到节点部分,这就是我将debug:true添加到我的连接任务的原因。然而,这似乎没有解决任何问题。

1 个答案:

答案 0 :(得分:2)

如果我正确理解了grunt-contrib.connect中的“port”,那么这就是网络服务器将响应的端口,而不是调试端口。

因此,在.vscode / launch.json中,您必须指定调试端口而不是Web服务器端口。由于grunt使用node,我假设调试端口是节点的默认端口5858。