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)) |
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 Javascript function sub(a, b) { return a-b } console.log(sub(6, 2)) |
Output:
4
Recommended Posts:
- Run Python script from Node.js using child process spawn() method
- Create a web server and run PHP script on it using Raspberry Pi
- Run Python Script using PythonShell from Node.js
- Top 5 Skills You Must Know Before You Learn ReactJS
- 13 Things You Should Know Before You Enter In Web Development
- How to print variable to the terminal in SASS ?
- How to run JavaScript from PHP?
- How to run a function when the page is loaded in JavaScript ?
- JavaScript : The Awesome Script
- Why split the <script> tag when writing it within document.write() method in JavaScript ?
- How to terminate a script in JavaScript ?
- How to use loop through an array in JavaScript?
- How to Display Changed Browser URL Without Reloading Through alert using JavaScript ?
- How to Draw Smooth Curve Through Multiple Points using JavaScript ?
- How do you display JavaScript datetime in 12 hour AM/PM format?
- 10 Amazing things you can build using JavaScript
- Why is Java 'write once and run anywhere'?
- How to run Cron Jobs in Node.js ?
- How to run two animations simultaneously in jQuery ?
- How to Run Synchronous Queries using sync-sql Module in Node.js ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


