Reputation: 5570
The project setup, is a basic express application, generated with express-generator.
The project, vscode-debugging-node is available at GitHub
Please refer the screencast at Visual studio Code - Debugging node application
The Gruntfile.js
in root of the project, manages the dev process. The purpose of the Gruntfile.js
is simple, it starts the server and watches for any file changes.
On detecting changes in the desired file(s), it restarts the server (kills the existing process and starts a new one).
The Gruntfile.js
uses ./task/server.js
to start/restart the server.
The Gruntfile.js
is developed in this manner, that later on, it will incorporate cookie management, in order to provide a logged in experience.
While executing the $ grunt start
task, if a env
variable named NODE_INSPECTOR=*
is passed, the server is started in --debug
mode.
When the grunt task is executed in --debug
mode, along with node-inspector
running in parallel, I can use Chrome to debug the complete application.
With reference to Debugging in Visual Studio Code, I tried to achieve the same by updating the .settings/launch.json
, with "program": "/usr/local/bin/grunt"
, "args": ["start"]
and "env": {"NODE_INSPECTOR":"*"}
.
I could find that debugger is attached only till ./task/server.js
but on the whole application. I doubt, it may be due to the spawn
ed server.
Is this possible to debug such situation in visual studio code? If yes, it will be of great help to know the details.
Upvotes: 4
Views: 4420
Reputation: 2364
Your doubts are correct, you are configuring Visual Studio Code to attach to the grunt task starting the server, not the server itself.
You have two options to order to debug this:
NODE_INSPECTOR=* grunt start
form the terminal.
Once the server has started, attach the the running server to the Debugger, using the same Attach configuration available in launch.json
. In the Debugger view choose the Attach from the profile dropdown and start the Debugger (green ► play button). UPDATE -- Sarbbotam recorded a screencast for successfully attaching to his node.js app, you can find it here Visual studio Code - Attaching a Node App to Debugger
program
option to "bin/www"
Upvotes: 3