My Development Notes

Programming Made Easier


How to run JavaScript codes inside VS Code

You can run JavaScript codes inside the Visual Studio Code’s in-built terminal. This saves time since you don’t have to open up an external browser every time to test-run your codes.

Here are the steps involved :

Step 1

You have to first check whether NodeJS is installed on your system. To check, just type node -v inside your terminal (on linux) or PowerShell (on Windows). If you don’t have it installed on your PC click here to download and install NodeJS.

Run the command again now to see the version (e.g., v16.3.7).

Step 2

Open your project folder in VS Code and go to the JavaScript file. Write a code and console log it as you usually do. I’ve written a simple multiply function and logged it to the console to see if it’s working:

Step 3

From the top panel, select Terminal >> New Terminal to open the in-built terminal :

Step 4

Type node<space>fileName and hit enter to test run your code and see if it works. In our example we type node app.js because app.js is our specific file name in this case :

It returns 12 ( 3 * 4 = 12 ) to the console.


Posted

in

by

Tags:

Leave a Reply