Is there a way to execute JavaScript and display the results using Visual Studio Code?
For example, a script file containing:
consol
Well, to simply run the code and show the output on the console you can create a task and execute it, pretty much as @canerbalci mentions.
The downside of this is that you will only get the output and thats it.
What I really like to do is to be able to debug the code, lets say Im trying to solve a small algorithm or trying a new ES6 feature, and I run it and there is something fishy with it, I can debug it inside VSC.
So, instead of creating a task for it, I modified the .vscode/launch.json file in this directory as follows:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${file}",
"stopOnEntry": true,
"args": [],
"cwd": "${fileDirname}",
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
}
]
}
What this does is that it will launch whichever file you are currently on, within the debugger of VSC. Its set to stop on start.
To launch it, press F5 key, in the file you want to debug.