How do you run JavaScript file through the Terminal?

There might be a situation when you need to check your JavaScript code without using browser, in that situation what should we do? First of all you might be surprised “JavaScript code without browser?”. Yes it is possible by using NodeJs Runtime Environment. You can run your JavaScript file through the terminal only if you have installed NodeJs runtime.

If you don’t have NodeJs runtime environment in your system then go to NodeJs Environment Download and download it. Next you have to create a JavaScript file and name it as Test.js.

Save your file and follow the below steps:

1. Open terminal or command prompt.
2. Set path to where file is located using cd command
3. Type “node Test.js” and hit enter(Without quotes).

Now you would see the output in the terminal as 50. This is how we run JavaScript file through the terminal. Isn’t it very easy? So next time you can test your JavaScript code without running the browser.

Leave a Reply

Your email address will not be published. Required fields are marked *