Visual Studio Code node.js debugging: "Connection failed" error Visual Studio Code node.js debugging: "Connection failed" error express express

Visual Studio Code node.js debugging: "Connection failed" error


I'm running VSCode v0.3.0 on GNU/Linux Ubuntu 12.04 LTS x64.


I can use the builtin VSCode debugger and use VSCode to attach to a node process running in debug mode.

You mentioned you are running debian/jessie GNU/Linux and Express and Node are listed in your tags so the following may be of some help.

Make sure you don't have any running node processes that would conflict with the connection by launching a System Monitor type application ( or app or command line tool of your choice ) and kill any node or nodejs processes that may not have been exited properly.

Double check your installation location of Mono and that it's version is v3.12 or higher (v4.0.1 or higher if developing for vNext ASP.net 5).

You can install Mono using any method you like as long as it's version is v3.12 or higher. I elected to download, compile and install Mono under /opt for my distribution from the mono-project.

15:15:34 ツ gjsmith3rd@DV7:~ >which mono /opt/mono/mono-4.0.1/bin/mono

15:15:38 ツ gjsmith3rd@DV7:~ >mono --versionMono JIT compiler version 4.0.1 (tarball Wed Jun 3 09:11:07 CDT 2015)Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: altstack Notifications: epoll Architecture: amd64 Disabled: none Misc: softdebug LLVM: supported, not enabled. GC: sgen

You'll want to take note of your Mono installation location for your environment configuration. In my case the location is /opt/mono/mono-4.0.1/*. You'll need to change the location to reflect your actual environment. Once you've determined the correct version and installation location ensure that the installation has correctly configured environment variables in your .bashrc, .bash_profile or relevant shell environment for your distribution.

```

export PATH=/opt/mono/mono-4.0.1/bin:$PATHexport MONO_LOG_LEVEL=debugexport MONO_LOG_MASK=asmexport LD_LIBRARY_PATH=/opt/mono/mono-4.0.1/lib:$LD_LIBRARY_PATHexport PKG_CONFIG_PATH=/opt/mono/mono-4.0.1/pkgconfigexport MONO_PATH=/opt/mono/mono-4.0.1/lib

```

Again, the paths need to reflect the locations in your environment. If you make any changes to your environment source your shell or logout and login.

$source .bashrc

Launch VSCode or close and relaunch VSCode.

In your VSCode debug config file (click the gear symbol in debug for Launch Configuration) launch.json make sure your app being debugged is node: "type": "node".

```

{    "version": "0.1.0",    // List of configurations. Add new configurations or edit existing ones.      // ONLY "node" and "mono" are supported, change "type" to switch.    "configurations": [        {            // Name of configuration; appears in the launch configuration drop down menu.            "name": "Launch server.js",            // Type of configuration. Possible values: "node", "mono".            "type": "node",            // Workspace relative or absolute path to the program.            "program": "server.js",            // Automatically stop program after launch.            "stopOnEntry": true,            // Command line arguments passed to the program.            "args": [],            // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.            "cwd": ".",            // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.            "runtimeExecutable": null,            // Environment variables passed to the program.            "env": { }        },         {            "name": "Attach",            "type": "node",            // TCP/IP address. Default is "localhost".            "address": "10.0.0.57",            // Port to attach to.            "port": 5858        }    ]}

```

Save any changes.

If you want to attach to a running node process then start the node app from the command line in the directory of your app.

$node debug appname.js

You can now use the node command line to continue the debugging process.

```

17:37:51 ツ gjsmith3rd@DV7:(master)~/Workspaces/Development/devsandbox >node debug server.js< Debugger listening on port 5858debug> . okbreak in server.js:5  3   4 //  OpenShift sample Node application> 5 var express = require('express');  6 var fs = require('fs');  7 // var bootstrap = require("bootstrap");debug> nextbreak in server.js:6  4 //  OpenShift sample Node application  5 var express = require('express');> 6 var fs = require('fs');  7 // var bootstrap = require("bootstrap");  8 debug> 

```

or launch VSCode and attach the debugger to the running node debug process. Make sure your VSCode Launch Configuration has an attach entry that is properly configured and run it from within VSCode by selecting the debugger pull down menu. You'll want to configure the IP and port to you requirements.

```

{                "name": "Attach",                "type": "node",                // TCP/IP address. Default is "localhost".                "address": "localhost",                // Port to attach to.                "port": 5858            }

```

Finally, you should be able to launch the debugger from VSCode without using the command line by using the VSCode debug pull down menu and selecting your configured JS or Node app and pressing the debugger play button.

Click the green play button in you VSCode debugger and it should open a terminal listing the debugging port while attaching to the process.

Debugger listening on port 38569

If all is well you should now be able to start the node app with the debugger controls within VSCode using the second play (continue) button (continue, step over, step into, step out and stop).