Sentinel
Sentinel

Reputation: 81

Running javascript from a bash script

I am new to learning bash script programming and was wondering if anyone here knows how can I execute javascript that would normally be embedded into an html page?

So from a bash script, I would like to execute ( for example ):

<script type="text/javascript" src="scriptName.js"></script>

Thank you very much for anyone's help.

Upvotes: 8

Views: 32231

Answers (2)

shin
shin

Reputation: 32721

How about using env like:

my-file

#!/usr/bin/env node

console.log("hello from test file");

Make the file executable.

chmod +x my-file

Then run it:

node my-file
hello from test file

Upvotes: 4

joews
joews

Reputation: 30310

You'll need a Javascript runtime like Node.js.

To evaluate a snippet of code: $ node -e "console.log('hello')"

To run a script: $ node script.js

Upvotes: 21

Related Questions