// Create a JS file - script.js and put below code
function sum(a, b) {
console.log(a + b);
}
sum(5, 10);
// run below command
// -> node script.js
If you have a Javascript file that you want to run in a Terminal window, there are a few steps you need to follow. First, open the Terminal application. Next, navigate to the directory where your Javascript file is located. Then, type the below command into the Terminal window:
node <filename.js>
Replace <filename.js> with the name of your Javascript file. Finally, press the Enter key to run the file.
Nodejs must be installed on your system to execute the Javascript file from the terminal.
0 Comments