Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging plain JavaScript code without web project

I have a JavaScript file that I'd like to edit and debug.

The code isn't DOM/browser/web specific.

Can I use VS Code to run and debug JavaScript without a web project like Node or ASP.NET? If so, how? Perhaps VS Code assumes it'll have a web server like Node to attach and debug

How should I modify my launch.json if necessary?

Loading a .js file and hitting F5 results in

Connection Failed

OpenDebug process has terminated unexpectedly

enter image description here

enter image description here

like image 781
p.campbell Avatar asked Mar 17 '23 05:03

p.campbell


1 Answers

I was having the same frustrating issue. The problem is node.exe is not in your PATH. You can check this by running cmd.exe, typing node and seeing if it runs or not. If it fails, this may help you:

Hit F5 in Code. It should create / open a launch.json file. In that file, change this line:

"runtimeExecutable": null,

to this:

"runtimeExecutable": "C:\\Program Files\\nodejs\\node.exe",

A more permanent solution would be to add node.exe to your PATH variable and reboot.

like image 113
redwards510 Avatar answered Mar 31 '23 20:03

redwards510