从bash脚本运行节点 [英] Running node from a bash script

查看:67
本文介绍了从bash脚本运行节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很简单,我试图使用cron自动运行nodejs脚本,但是脚本本身似乎无法运行该文件.我的脚本很简单:

Quite simply, I'm attempting to automate running a nodejs script using cron, however the script itself doesn't seem to be able to run the file. My script is simple:

#!/usr/bin/env node
node /var/node/assets/js/update.js

但是,在运行此命令时,它会返回路径的开头不正确:

However, in running this, it returns that the beginning of the pathing is incorrect:

/home/dev/update.sh:2
node /var/node/assets/js/update.js
      ^^^
SyntaxError: Unexpected token var
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

bash是否确实存在问题,或者节点是否有特定的方法来执行此操作?我使用了/bin/env,以便无论版本如何,我都可以使用正确的形式的节点".

Is there something actually wrong with the bash, or does node have a specific way of doing this? I used /bin/env so that I could have the proper form of "node" regardless of version.

推荐答案

您似乎正在尝试从node内部运行node.错误消息来自节点,看起来节点正在尝试运行命令/var/node/assets/js/update.js .

It looks like you are trying to run node from within node. The error message came from node and it looks like node was trying to run the command /var/node/assets/js/update.js.

我会让shebang行指定bash而不是node.

I would make the shebang line specify bash rather than node.

第一行

#!/usr/bin/env node

意味着后面应该是JavaScript代码,而不是bash.

means that what follows should be JavaScript code, not bash.

这篇关于从bash脚本运行节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆