title: Debugging a node app hosted on a VM using Visual Studio Code
body: <p>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. </p>
  
  <p>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).</p>
  
  <p>However in VSC if I use the "attach" option in debug I cannot get to a breakpoint at all.</p>
  
  <p>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?</p>
  
  <p>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:</p>
  
  <p>Inside the VM:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Embedding-Host: node v0.10.32
  Content-Length: 0</p>
  
  <p>Outside the VM:</p>
  
  <pre><code>telnet 127.0.0.1 5858
  Trying 127.0.0.1...
  Connected to localhost.
  Escape character is '^]'.
  Connection closed by foreign host.
  </code></pre>
  
  <p>Any help would be much appreciated?</p>
  
  <hr>
  
  <p>Yes I'm running VSCode outside the VM - The VM is headless.</p>
  
  <p>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. </p>
  
  <p>However I've tried a different approach. I've tunnelled a connection via ssh for all the traffic on port 5858:</p>
  
  <pre><code>ssh -i myprivatekey -L 5858:localhost:5858 tempuserlocalhost -p 2222 
  </code></pre>
  
  <p>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. </p>
  
  <p>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:</p>
  
  <pre><code>Error opening 'app.js' (File not found)
  </code></pre>
  
  <p>Note: app.js and the other code files are <strong>not</strong> held on the VM, they are held on my local machine with samba shares configured accordingly. Perhaps this is causing the confusion?</p>