Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

shell - Is it possible to run JavaScript files from the command line?

I have several JS files so instead of copy and paste every one in the console window (Firefox and Chromium), I would want to call them from the shell if it is possible.

Every JS file has test functions that show if they are correct using console.log.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

Node REPL (Shell)

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:

Evaluate a JavaScript file


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...