How To Run JavaScript In VSCode

How To Run JavaScript In VSCode

Executing JavaScript files from VSCode terminal (command line)

·

2 min read

If you're working on a JavaScript project in VSCode, you might want to run your JavaScript files directly from the terminal. This is especially useful when you want to test a specific script file or to see if your JavaScript function works without running entire project.

Here's the original article on running javascript in vscode (visual studio code)

Below are some videos that can help you get started fast.

Running JavaScript Files In Visual Studio Code

How To Run JavaScript In VSCode

Luckily, Visual Studio Code makes it easy to do this. All you need to do is open up your terminal (Ctrl+`), and then type the following:

> node {filename}

Replace {filename} with the name of your javascript file. For example, if your file is named "script.js", you would type:

> node script.js

This will run your javascript file and show any output in the terminal window.

Keep in mind that you can also use this method to run javascript files that are located in a different directory. To do this, simply type the path to the file before the filename. For example:

> node C:/Users/username/Desktop/script.js

This would run the javascript file "script.js" that is located on your Desktop.

You can also use relative paths to run javascript files that are located in different directories. Relative paths are based on the current location of your terminal. So, if your javascript file is located in a folder called "js" that is in the same directory as your terminal, you could run it by typing:

> node js/script.js

This would run the javascript file "script.js" that is located in the "js" folder.

You can also use the "../" notation to go up one directory. So, if your javascript file is located in a folder called "js" that is in the parent directory of your terminal, you could run it by typing:

> node ../js/script.js

This would run the javascript file "script.js" that is located in the "js" folder.

Hopefully this helps you run javascript files from the vscode terminal!