Register Login

Run JavaScript in Windows Terminal

Updated Nov 21, 2022

A terminal is simply a text-based interface to the computer where one can type commands, manipulate files, and execute programs. We'll learn how to run JavaScript in the terminal. To be able to run JavaScript files in the terminal, the system must have node.js already installed in it.

to install node.js on windows please use the given below link.

How to Install node.js

Running a JavaScript file in the terminal.

After finishing the installation process of node.js, let's go through some examples:

  1. Open the terminal window
  2. Type node then hit enter
  3. The dialogue- Welcome to node,j shall appear followed by the greater than symbol(>)

#1 example:

Code:

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

Output:

#2 example:

  1. Open the terminal window
  2. Type node then hit enter
  3. The dialogue- Welcome to node,j shall appear followed by the greater than symbol(>)

Code:

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

Output:

Conclusion:

A terminal is a non-graphical text-based interface where one manipulates files or programs by entering commands. From the above article, we conclude that:

  1. First, installation of node.js in the system is necessary before running JavaScript in the terminal.
  2. node.js is not a programming language or framework. It is an open-source environment to run JavaScript files outside a browser (Follow the step-by-step instruction to install node.js mentioned above)
  3. Sometimes one may need to update the npm package manager for the smooth functioning of the JavaScript file.


×