Visual Studio Code - Debugging a spawned process

sarbbottam

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 spawned server.


Is this possible to debug such situation in visual studio code? If yes, it will be of great help to know the details.

Sofian Hnaide

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:

  1. Execute 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

  1. Configure VSCode to run the server directly, for that you won't have the grunt task listening to the changes and restarting the server. In order to do that change the program option to "bin/www"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Visual Studio Code debugging with AngularJS

From Dev

Visual Studio Code debugging client side JavaScript

From Dev

debugging in Visual Studio Code with babel-node

From Dev

Set protractor arguments debugging in visual studio code

From Dev

Debugging Scrapy Project in Visual Studio Code

From Dev

Execute code only while debugging with Visual Studio

From Dev

Debugging MSTest Unittests in Visual Studio Code

From Dev

Remote debugging a process that crashes on launch using Visual Studio 2012

From Dev

Debugging Dump code of a process

From Dev

Debugging Dump code of a process

From Dev

Debugging xUnit tests in .NET Core and Visual Studio Code

From Dev

Debugging Electron-Atom script with Visual Studio Code

From Dev

Pressing break while debugging in Visual Studio - annoying "Code Not Running"

From Dev

Debugging in Unity (C#) + Visual Studio Code Work on OS X?

From Dev

Debugging a node app hosted on a VM using Visual Studio Code

From Dev

Debugging node.js in Visual Studio Code preview on OS X

From Dev

Can't step over code in Visual studio while debugging

From Dev

Debugging Electron-Atom script with Visual Studio Code

From Dev

GUI Debugging server app using Visual Studio Code

From Dev

SPFx breakpoints and debugging from Visual Studio Code instead from Chrome

From Dev

Dynamic debugging with visual studio

From Dev

Visual Studio debugging WebApi

From Dev

Visual Studio debugging WebApi

From Dev

Dynamic debugging with visual studio

From Dev

Debugging Visual Studio

From Dev

Visual Studio 2015 Debugging vs Not Debugging Views

From Dev

How to get the exit code of spawned process in expect shell script?

From Dev

Expect: How to get the exit code from spawned process

From Dev

Keyboard shortcuts not working after process attach (Visual Studio 2013 bug during debugging)

Related Related

  1. 1

    Visual Studio Code debugging with AngularJS

  2. 2

    Visual Studio Code debugging client side JavaScript

  3. 3

    debugging in Visual Studio Code with babel-node

  4. 4

    Set protractor arguments debugging in visual studio code

  5. 5

    Debugging Scrapy Project in Visual Studio Code

  6. 6

    Execute code only while debugging with Visual Studio

  7. 7

    Debugging MSTest Unittests in Visual Studio Code

  8. 8

    Remote debugging a process that crashes on launch using Visual Studio 2012

  9. 9

    Debugging Dump code of a process

  10. 10

    Debugging Dump code of a process

  11. 11

    Debugging xUnit tests in .NET Core and Visual Studio Code

  12. 12

    Debugging Electron-Atom script with Visual Studio Code

  13. 13

    Pressing break while debugging in Visual Studio - annoying "Code Not Running"

  14. 14

    Debugging in Unity (C#) + Visual Studio Code Work on OS X?

  15. 15

    Debugging a node app hosted on a VM using Visual Studio Code

  16. 16

    Debugging node.js in Visual Studio Code preview on OS X

  17. 17

    Can't step over code in Visual studio while debugging

  18. 18

    Debugging Electron-Atom script with Visual Studio Code

  19. 19

    GUI Debugging server app using Visual Studio Code

  20. 20

    SPFx breakpoints and debugging from Visual Studio Code instead from Chrome

  21. 21

    Dynamic debugging with visual studio

  22. 22

    Visual Studio debugging WebApi

  23. 23

    Visual Studio debugging WebApi

  24. 24

    Dynamic debugging with visual studio

  25. 25

    Debugging Visual Studio

  26. 26

    Visual Studio 2015 Debugging vs Not Debugging Views

  27. 27

    How to get the exit code of spawned process in expect shell script?

  28. 28

    Expect: How to get the exit code from spawned process

  29. 29

    Keyboard shortcuts not working after process attach (Visual Studio 2013 bug during debugging)

HotTag

Archive