Skip to content
Related Articles

Related Articles

How do you run JavaScript script through the Terminal?

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Easy
  • Last Updated : 29 Mar, 2022

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


// Simple Addition Function in Javascript
function add(a, b) {
return a+b
console.log(add(4, 6))



Steps :

  1. Open Terminal or Command Prompt.
  2. Set Path to where File is Located (using cd).
  3. Type “node New.js” and Click Enter

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


// Simple Subtraction Function in Javascript
function sub(a, b) {
return a-b
console.log(sub(6, 2))



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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!