Is there a way to execute JavaScript and display the results using Visual Studio Code?
For example, a script file containing:
consol
This is the quickest way for you in my opinion;
View > Integrated Terminal
)'node filename.js'
note: node setup required. (if you have a homebrew just type 'brew install node' on terminal)
note 2: homebrew and node highly recommended if you don't have already.
have a nice day.
I am surprised this has not been mentioned yet:
Simply open the .js
file in question in VS Code, switch to the 'Debug Console' tab, hit the debug button in the left nav bar, and click the run icon (play button)!
Requires nodejs to be installed!
Another option is to use the developer tools console within Visual Studio Code. Simply select "Toggle Developer Tools" from the help menu and then select the "Console" tab in the developer tools that pop up. From there you have the same dev tools REPL that you get in Chrome.
This may now be the easiest, as of v1.32:
{
"key": "ctrl+shift+t",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "node '${file}'\u000D" }
}
Use your own keybinding.
See Release notes: sendSequence and variables.
With vscode v1.32 you can sendSequence
to the terminal using variables like ${file}
, which is the current file. If you want some other path there, replace ${file} with your pathname in the keybinding above.
The \u000D
is a return so it will run immediately.
I added '
s around the ${file}
variable in case your file path has spaces in it,
like c:Users\Some Directory\fileToRun
I faced this exact problem, when i first start to use VS Code with extension Code Runner
The things you need to do is set the node.js path in User Settings
You need to set the Path as you Install it in your Windows Machine.
For mine It was \"C:\\Program Files\\nodejs\\node.exe\"
As I have a Space in my File Directory Name
See this Image below. I failed to run the code at first cause i made a mistake in the Path Name
Hope this will help you.
And ofcourse, Your Question helped me, as i was also come here to get a help to run JS
in my VS CODE
I used Node Exec, no config needed, builds the file that you are currently ending or what ever has been selected and outputs inside of VSCode.
https://marketplace.visualstudio.com/items?itemName=miramac.vscode-exec-node
With a bit of config you can add Babel to do some on the fly transpiling too.