运行 服务器上的 Crontab 没有 运行 节点脚本

Crontab doesn't run node script on ubuntu server

我正在尝试 运行 节点脚本作为 Ubuntu 14.04 服务器上的 CRON 作业。我正在使用 nvm.

我试过:

* * * * * /usr/bin/env node /var/www/apps/gmail-api/exe/m.js recent x@x.x

以及:

* * * * * node /var/www/apps/gmail-api/exe/m.js recent x@x.x

最后:

* * * * * ~/.nvm/bin/node-v6.6.0-linux-x64 /var/www/apps/gmail-api/exe/m.js recent x@x.x

都没用。

但是如果我运行:

node /var/www/apps/gmail-api/exe/m.js recent x@x.x

它工作正常。

为什么 crontab 运行 我的脚本没有?

我的解决方法:

我在 pm2forever npm 模块中创建了 运行 脚本。

setInterval(()=>{
  child_process.exec('node scriptname.js arg1 arg2', (err, stdout, stderr)=>{
    if (err) {
      console.log(err);
    }
    console.log(stdout);
    console.log(stderr);
  });
}, 60000)