Visual Studio Code - Debugging a Spawned Process

Project setup is a basic express application built with express generator.

The project, vscode-debugging-node is available on GitHub

Please refer to the screencast in Visual Studio Code - Debug node app


Gruntfile.js

at the root of the project, manages the dev process. The goal Gruntfile.js

is simple, start the server and watch for any file changes. When it detects changes in the desired file (s), it restarts the server (kills the existing process and starts a new one).

Gruntfile.js

uses ./task/server.js

to start / restart the server.

Gruntfile.js

is designed in such a way that it will later include cookie management to provide a logged experience.

When executing the task $ grunt start

, if a variable env

with a name is passed NODE_INSPECTOR=*

, the server starts up in --debug

mode
. With the grunt task running in mode --debug

and node-inspector

running in parallel in parallel, I can use Chrome to debug the complete application.


Regarding Debugging in Visual Studio Code , I tried to achieve the same by updating .settings/launch.json

, with "program": "/usr/local/bin/grunt"

, "args": ["start"]

and "env": {"NODE_INSPECTOR":"*"}

.

I could find that the debugger is tied only before ./task/server.js

, but for the whole application. I doubt it might be due to the spawn

ed server
.


Is it possible to debug this kind of situation in visual studio code ? If so, it will be very helpful to know the details.

+3


source to share


1 answer


Your doubts are correct, you are configuring Visual Studio Code to attach to the grunt task starting from the server, not from the server itself.

You have two options to debug this:

  • Run NODE_INSPECTOR=* grunt start

    form a terminal. After starting the server, attach the current server to the Debugger using the same Attach configuration available in launch.json

    . In the Debugger view, select Attach from the profile drop-down list and launch the Debugger (green ► play button).


UPDATE - Sarbbotam recorded a screencast to successfully attach to their node.js app, you can find it here Visual studio Code - Attaching a Node app to the debugger

  1. Configure VSCode to start the server directly, for which you will not have a grunt task listening for changes and restarting the server. To do this, change the option program

    to"bin/www"

+3


source







All Articles