Debug current file in VS code

I am writing javascript and am currently doing simple exercises / programs. From time to time I want to run a file for testing. I know that I can create an HTML file and do it in the console. In Sublime, there is a way to “build” the current file and immediately see the results (say, everything sent to console.log).

With VS Code, it seems that for every file I want to build / debug in this way, I have to manually modify the launch.json file to display the name of the current program.

I researched the way of this and I found out that there are variables like ${file} , but when I use this in the launch.json attribute "program", for example:

 "program": "${workspaceRoot}/${file}" 

with or without the workspaceRoot part, I get the following error:

 Attribute "program" does not exist" (file name here). 

Am I missing a simple way to accomplish this, or should I constantly edit launch.json every time I want to run a file?

Thanks in advance!

+13
javascript visual-studio-code
source share
3 answers

Change to:

 "program": "${file}" 
+47
source share

For reference, this is the full launch.json

 { "version": "0.2.0", "configurations": [ { "type": "node", "request": "launch", "name": "Debug File", "program": "${file}" } ] } 
+9
source share

For a single file, you can completely skip the launch.json file. Just click the green arrow in the debugger panel and select Node as your environment.

From here

0
source share

All Articles