Run JavaScript in Visual Studio Code

Is there a way to execute JavaScript and display the results using Visual Studio Code?

For example, a script file containing:

console.log('hello world');

I assume that Node.js would be needed but can't work out how to do it?

By Visual Studio Code I mean the new Code Editor from Microsoft - Not code written using Visual Studio.


There is a much easier way to run JavaScript, no configuration needed:

  1. Install the Code Runner Extension
  2. Open the JavaScript code file in Text Editor, then use shortcut Control+Alt+N (or ⌃ Control+⌥ Option+N on macOS), or press F1 and then select/type Run Code, the code will run and the output will be shown in the Output Window.

Besides, you could select part of the JavaScript code and run the code snippet. The extension also works with unsaved files, so you can just create a file, change it to Javascript and write code fast (for when you just need to try something quick). Very convenient!

NodeJS is needed for this else it will not work.


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!