从bash脚本运行javascript

时间:2014-06-12 11:35:13

标签: javascript bash

我是学习bash脚本编程的新手,想知道我是否知道如何执行通常嵌入到html页面的javascript?

所以从bash脚本开始,我想执行(例如):

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

非常感谢任何人的帮助。

2 个答案:

答案 0 :(得分:9)

您需要像Node.js这样的Javascript运行时。

评估一段代码:$ node -e "console.log('hello')"

运行脚本:$ node script.js

答案 1 :(得分:0)

使用 env 怎么样:

我的文件

#!/usr/bin/env node

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

使文件可执行。

chmod +x my-file

然后运行它:

node my-file
hello from test file