How do you run JavaScript script through the Terminal?
You can Run your JavaScript File from your Terminal only if you have installed NodeJs runtime. If you have Installed it then Simply open the terminal and type “node FileName.js”. If you don’t have NodeJs runtime environment then go to NodeJs Runtime Environment Download and Download it.
Example 1: Create a JavaScript File Name this file as New.js.
Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!
// Simple Addition Function in Javascriptfunction add(a, b) {return a+b}console.log(add(4, 6)) |
Output:
10
Steps :
- Open Terminal or Command Prompt.
- Set Path to where File is Located (using cd).
- Type “node New.js” and Click Enter
Examples 2: Create a JavaScript File Name this file as New2.js.
// Simple Substraction Function in Javascriptfunction sub(a, b) {return a-b}console.log(sub(6, 2)) |
Output:
4
JavaScript is best known for web page development but it is also used in a variety of non-browser environments. You can learn JavaScript from the ground up by following this JavaScript Tutorial and JavaScript Examples.

