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

Nicholas Ford

I'm looking for a little help in debugging my app using Visual Studio Code, where my app is held in a virtual machine hosted by Oracle Virtual Box.

The VM has been provisioned with a typical setup of node, express, node-inspector etc. and I am able to debug my app using node-inspector (i.e. the port for node-inspector has been forwarded within the vm and if I set my app running with "node --debug-brk app.js" it listens on port 5858 and I can navigate to localhost:8080/debug?port=5858 to start debugging).

However in VSC if I use the "attach" option in debug I cannot get to a breakpoint at all.

Is there something special that I am missing here or are there any log files I can look at - I'm on OSX Yosemite and the VM OS is running in virtual box is a headless OpenSuse, provisioned with vagrant?

NB: I have tried telnetting to the VM on port 5858 and I get a different response from within the VM to the local machine itself, as indicated below:

Inside the VM:

telnet 127.0.0.1 5858
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Type: connect
V8-Version: 3.14.5.9
Protocol-Version: 1

Embedding-Host: node v0.10.32 Content-Length: 0

Outside the VM:

telnet 127.0.0.1 5858
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

Any help would be much appreciated?


Yes I'm running VSCode outside the VM - The VM is headless.

The ports are already configured to be forwarded inside the vagrant provisioning script. However a colleague has informed me that there might be a company policy that is being forced upon us relating to our network adapters - preventing/causing my connection issue.

However I've tried a different approach. I've tunnelled a connection via ssh for all the traffic on port 5858:

ssh -i myprivatekey -L 5858:localhost:5858 tempuserlocalhost -p 2222 

Now when I start debugging the app (i.e. node --debug app.js) and use the attach option the debugger clearly attaches. It doesn't hit my breakpoint in app.js though, when it should do.

In actual fact if I pause the debugger I get a list of the local variables and a call stack but the following error is shown:

Error opening 'app.js' (File not found)

Note: app.js and the other code files are not held on the VM, they are held on my local machine with samba shares configured accordingly. Perhaps this is causing the confusion?

Andre Weinand

I have verified that tunnelling the port 5858 via ssh works in so far that you can connect to node running inside the VM and use debugger functionality that does not involve source paths (Source paths are used for breakpoints and step events, etc.) The problem with source paths is that VSCode needs access to the source files with the same paths as node running inside the VM. Even if you share the source through samba, the absolute path leading to a file might be different between inside of the VM and outside. The only workaround for VSCode Preview is to make the paths identical e.g. by introducing (symbolic) links etc. I have create a bug on our side to improve the source path matching.

Andre Weinand, Visual Studio Code

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

GUI Debugging server app using Visual Studio Code

From Dev

debugging in Visual Studio Code with babel-node

From Dev

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

From Dev

Visual Studio Code debugging with AngularJS

From Dev

Debugging with visual studio multi-threaded app

From Dev

Visual Code (NODE JS) debugging - variables are invisible

From Dev

Visual Studio Code - Debugging a spawned process

From Dev

Visual Studio Code debugging client side JavaScript

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

How to configure visual studio code for debugging aps.net 5 sample app

From Dev

Defining types in Node.JS using Visual Studio Code

From Dev

Console Window Appears while debugging Python code using PTVS in Visual Studio

From Dev

How can I edit my code while debugging using Visual Studio?

From Dev

Debugging Console App and Web API App from Visual Studio 2010

From Dev

Writing and debugging C code using Xamarin Studio

From Dev

Debugging unit tests in Node Tools Visual Studio (NTVS)

From Dev

Javascript Proxy (Node) in Visual Studio 2017 Causes Blocking When Debugging

From Dev

Unable to start debugging in Visual Studio RTM for cordova app

From Dev

Debugging WebApi in Visual Studio returns no response to MVC app

From Dev

Debugging Cordova App (android) with Visual Studio 2015 New Emulator

From Dev

Unable to start debugging in Visual Studio RTM for cordova app

From Dev

Debugging Appcelerator Windows Phone App with Visual Studio 2015

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?

Related Related

  1. 1

    GUI Debugging server app using Visual Studio Code

  2. 2

    debugging in Visual Studio Code with babel-node

  3. 3

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

  4. 4

    Visual Studio Code debugging with AngularJS

  5. 5

    Debugging with visual studio multi-threaded app

  6. 6

    Visual Code (NODE JS) debugging - variables are invisible

  7. 7

    Visual Studio Code - Debugging a spawned process

  8. 8

    Visual Studio Code debugging client side JavaScript

  9. 9

    Set protractor arguments debugging in visual studio code

  10. 10

    Debugging Scrapy Project in Visual Studio Code

  11. 11

    Execute code only while debugging with Visual Studio

  12. 12

    Debugging MSTest Unittests in Visual Studio Code

  13. 13

    How to configure visual studio code for debugging aps.net 5 sample app

  14. 14

    Defining types in Node.JS using Visual Studio Code

  15. 15

    Console Window Appears while debugging Python code using PTVS in Visual Studio

  16. 16

    How can I edit my code while debugging using Visual Studio?

  17. 17

    Debugging Console App and Web API App from Visual Studio 2010

  18. 18

    Writing and debugging C code using Xamarin Studio

  19. 19

    Debugging unit tests in Node Tools Visual Studio (NTVS)

  20. 20

    Javascript Proxy (Node) in Visual Studio 2017 Causes Blocking When Debugging

  21. 21

    Unable to start debugging in Visual Studio RTM for cordova app

  22. 22

    Debugging WebApi in Visual Studio returns no response to MVC app

  23. 23

    Debugging Cordova App (android) with Visual Studio 2015 New Emulator

  24. 24

    Unable to start debugging in Visual Studio RTM for cordova app

  25. 25

    Debugging Appcelerator Windows Phone App with Visual Studio 2015

  26. 26

    Debugging xUnit tests in .NET Core and Visual Studio Code

  27. 27

    Debugging Electron-Atom script with Visual Studio Code

  28. 28

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

  29. 29

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

HotTag

Archive