Run JavaScript In VSCode
Code Something
Posted on August 4, 2022
Hey guys! So just been posting several of my coding tutorials in a row that I've been working on for a while.
I like to spend time writing and editing my content. So I usually record a video along with a blog post.
VSCode is absolutely my favorite IDE. (I switched from IntelliJ/Idea WebStorm which used to be my first IDE, but their UI is just too slow for me) I use it for pretty much all coding for work and personal projects.
Running JavaScript From Terminal in VSCode
If you're working on a JavaScript project in VSCode, you might want to run your JavaScript files directly from the terminal.
Below are some videos that can help you get started fast.
How To Run JavaScript In VSCode Video #1
How To Run JavaScript In VSCode Video #2
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!
Posted on August 4, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.