1

I'm unable to use Visual Studio Code to debug my node application.

My .vscode/launch.json looks like this:

{
  "version": "0.2.0",
  "configurations": [{
    "name": "Attach",
    "type": "node",
    "request": "attach",
    "port": 9001
  }]
}

I use grunt-contrib-connect to start my web server. My connect task is defined my my gruntfile.js like this:

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

After successfully starting the web server with the above task, I try to attach from VSCode, but apart from some UI flashes, nothing seems to happen. No breakpoints are hit.

I read the VS Code Debugging Documentation, especially the Attaching VS Code to Node section, which is why I added the debug:true to my connect task. However this did not seem to fix anything.

V Maharajh
  • 9,013
  • 5
  • 30
  • 31

1 Answers1

2

If I understand the "port" in grunt-contrib.connect correctly, then this is the port on which the webserver will respond, not the debugging port.

So in your .vscode/launch.json you must specify the debug port not the webserver port. Since grunt uses node, I assume the debug port is node's default port 5858.

Andre Weinand
  • 1,907
  • 11
  • 8
  • That seemed to get me further. However, VS Code now fails to attach with: "cannot connect to runtime process (timeout after 5000ms)" – V Maharajh Dec 03 '15 at 18:49
  • I don't think that the "debug: true" does the right thing. The grunt-contrib-connect doc says: "Set the debug option to true to enable logging instead of using the --debug flag." This does not sound like node debugging. I've never used grunt but most likely you have to launch grunt in debug mode like this: "node --debug-brk $(which grunt) ". – Andre Weinand Dec 04 '15 at 14:07
  • Hmm. That allowed me to use VS Code to debug grunt itself, not my website. – V Maharajh Dec 04 '15 at 16:40
  • I suggest that you try to find out how to debug a grunt based webserver in general. I'm familiar with VS Code (because I'm the dev), and I know how to configure VS Code, but I have no idea how to configure grunt for debugging webservers... – Andre Weinand Dec 05 '15 at 19:12