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

Visual Studio Code Get started with web development by learning how to use HTML, CSS, and JavaScript to build a website, use developer tools in the browser to check your work. Learning objectives. Working with JavaScript IntelliSense #. Visual Studio Code's JavaScript IntelliSense provides intelligent code completion, parameter info. JavaScript projects (jsconfig.json) #. The presence of a jsconfig.json file in a directory indicates that the directory. Type checking JavaScript #.

I'm using Visual Studio 2008 for doing work in C# and JavaScript (AJAXy stuff). Here's my issue - I love Eclipse and especially the code formatted (Ctrl-Shift-F). Visual Studio's Ctrl-k, Ctrl-d, really sucks in comparison, especially for javascript. Is there a way to get VS to behave like the IDE that I miss? Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free and available on your favorite platform.

I assume that nodejs would be needed but can’t work out how to do it?

EDIT: By “Visual Studio Code” I mean the new Code editor from Microsoft – Not code written using Visual Studio

Answers:

This solution intends to run currently open file in node and show output in VSCode.

I had the same question and found newly introduced tasks useful for this specific use case. It is a little hassle, but here is what I did:

Create a .vscode directory in the root of you project and create a tasks.json file in it. Add this task definition to the file:

Then you can:
press F1 > type `run task` > enter > select `runFile` > enter
to run your task, but I found it easier to add a custom key binding for opening tasks lists.

To add the key binding, in VSCode UI menu, go ‘Code’ > ‘Preferences’ > ‘Keyboard Shortcuts’. Add this to your keyboard shortcuts:

Of course you can select whatever you want as key combination.

UPDATE:

Assuming you are running the JavaScript code to test it, you could mark your task as a test task by setting its isTestCommand property to true and then you can bind a key to the workbench.action.tasks.test command for a single-action invocation.

Vscode

In other words, your tasks.json file would now contain:

…and your keybindings.json file would now contain:

How to run javascript in visual studio code

Visual Studio Code Js

Answers:

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 Ctrl+Alt+N, 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. Very convenient!

Answers:

The shortcut for the integrated terminal is (ctrl+`), then type node <filename>.

Alternatively you can create a task. This is the only code in my tasks.json:

From here create a shortcut. This is my keybindings.json:

This will open ‘run’ in the Command Pallete, but you still have to type or select with the mouse the task you want to run, in this case node. The second shortcut toggles the output panel, there’s already a shortcut for it but these keys are next to each other and easier to work with.

Answers:

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:

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.

Answers:

It’s very simple, when you create a new file in VS Code and run it, if you already don’t have a configuration file it creates one for you, the only thing you need to setup is the “program” value, and set it to the path of your main JS file, looks like this:

Answers:

Javascript Extension In Visual Studio 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.

With a bit of config you can add Babel to do some on the fly transpiling too.

Tags: java, javascript