To run JavaScript in Terminal, first install
Node.js
, then run your JavaScript file like so: node file.js
.First, install Node.js, so you could run node
command in your Terminal.
On a Mac, you can do it via Homebrew:
brew install node
Then create a JavaScript file named test.js
with this content:
console.log('Hello World!');
Finally, run node
with this file:
node test.js
And you will see this printed in the Terminal:
Hello World!