Hi, need help! how to run Javascript, code or program in Visual Studio Code?

Visual Studio Code (VSC) is one of the most popular and widely used code editors used by developers. Even our team here at Letstacle uses visual studio code for most of our daily work. And we love it.

Run JavaScript in Visual Studio Code

We all know that JavaScript is built for browsers and is mainly used to make webpage interactive. However, this is not completely true. JavaScript program can run outside of a browser, using Node JS.

You can read more on JavaScript and know and the difference between Java and JavaScript.

1.Installing Node JS

To run a javascript file in Visual Studio Code you must have Node JS installed on your machine( Windows, Mac, Linux ).

node js download page

  • First, download the latest stable release from the official website.
  • Once downloaded, run the installer and complete the installation process.

2. Verify Node Installation

Once the installation is complete, its time to  make sure it is available.

To verify if Node is installed or not follow the step below.

Open your Cmd in Windows or Terminal on Mac. And check for the Node version using the command-

node -v

node version check cmd

If you get the Node version it means that Node is successfully installed and is available in your system.

Perfect till now!!, follow the 3rd step.

3. Run JavaScript in Visual Studio Code

  • Open your Visual Studio Code editor.
  • Create a new file.
  • Write a JavaScript code.

JavaScript code in visual studio code

 

  • Make sure to Save the code.
  • Open the terminal in Visual Studio Code.

 

terminal in vsc

 

  • Once you have the terminal open.
  • Use the cd command to change the directory and navigate to the directory/folder you have saved your JavaScript program file.
  • Finally, to Run JavaScript in Visual Studio Code terminal. Use the below command-
node filename.js

run javascript in visual studio code

You can see the JavaScript program output on your visual studio code terminal window.

Kudos! you have your first JavaScript code running successfully in VSC.

Like this article? Follow us on Facebook and LinkedIn. You can also subscribe to our weekly Feed.