Heapcoding

How Quickly Run JavaScript in Visual Studio Code?

Published February 1, 2021

In this tutorial I shall teach you how to run JavaScript in visual studio code. For this tutorial I am using Linux, Ubuntu operating system. So I shall mostly use a terminal to install some of the programs.

Before running Javascript in visual studio code, we need to install NodeJs in our machine. For this follow the below steps to installing the NodeJs.

sudo npm install nodejs

If you already installed then the the following things will be shown in the screenshot below.

how to run javascript in visual studio code
how to run javascript in visual studio code

Then check the npm and node version by typing the following commands

node -v

npm -v

how to run javascript in visual studio code
how to run javascript in visual studio code

The above result will be shown when you type those two commands to check the node and npm version.

Now you need to install the Visual Studio Code into your computer. There are also very simple steps to installing the Visual Studio code into your machine.

Simply type the following command to install the Visual Studio code to your machine.

sudo snap install code –classic

And now you are ready to run your first JavaScript program in Visual Studio Code.

Now follow these steps to run JavaScript in Visual Studio Code.

Step 1

Open Visual Studio code program

how to run javascript in visual studio code
how to run javascript in visual studio code

When you install it for the first time in your computer the above display will be of Visual Studio Code.

Step 2

Now Create a folder on the desktop which is named “js-program”. Go to File -> Open Folder And select the folder which you created from desktop by using the browser window. And click ok.

Now that folder will be opened to your Visual Studio Code Like below screenshot.

how to run javascript in visual studio code
how to run javascript in visual studio code

Step 3

Now right click on below of your folder name and click on “new file” option. And name that file as “index.js”. And hit Enter key a new file will be opened to your web browser like the below screenshot.

how to run javascript in visual studio code
how to run javascript in visual studio code

Step 4

Now write the code like below screenshot in that “index.js” file.

how to run javascript in visual studio code
how to run javascript in visual studio code

Step 5

Press “CTRL+S” Key to save the file. 

Now go to terminal -> new terminal to open and create a new terminal window. On the bottom side of your Visual Studio Code a tab will be shown like the screenshot below.

how to run javascript in visual studio code
how to run javascript in visual studio code

Step 6

In terminal type the following commands to run your index.js file.

node index.js

When you type the above command the “Hello JavaScript” message will be shown after the command which you have written in your “index.js” file, like the screenshot below.

how to run javascript in visual studio code
how to run javascript in visual studio code

Congratulations!

You have learned “how to run JavaScript in visual studio code”.