Expanding upon the solution to use Node.js…
Here are some examples and screenshots from a page on Command Line JavaScript.
The Node REPL (Shell)
If you enter node
on the command line with no arguments, you'll be in the Read-Eval-Print-Loop, or REPL for short, otherwise known as a shell. Here you can interactively enter JavaScript expressions and have them immediately evaluated.
Evaluate a JavaScript file from the command line
Create a file with the following content:
console.log('Hello, world');
From the command line, use node
to evaluate the file:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…