Friday, September 5, 2025
HomeLanguagesJavascriptHow do you run JavaScript script through the Terminal?

How do you run JavaScript script through the Terminal?

You can run your JavaScript file from your terminal only if you have installed Node.Js in your system. Install Node.js from Steps to install Node.js.

If you have already installed it, then simply open the terminal and type “node <FileName>.js”.

Example 1: Create a JavaScript file. Name this file as New.js

javascript




// Function to add two variables.
 
const add = (a, b) => {
    return a + b
}
 
console.log(add(4, 6))


Output:

10

Steps :

  1. Open Terminal or Command Prompt.
  2. Set Path to where New.js is located (using cd).
  3. Type “node New.js” and press ENTER.

Example 2: Create a JavaScript File Name this file as New2.js

javascript




// Function to subtract two variables.
 
const sub = (a, b) => {
    return a - b
}
 
console.log(sub(6, 2))


Output:

4

JavaScript is best known for web page development but is also used in various non-browser environments. You can learn about JavaScript from the ground up by following JavaScript Tutorial and JavaScript Examples.

RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11866 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS