How can you execute a Node.js script via a cron job?

后端 未结 7 1549
深忆病人
深忆病人 2020-12-02 08:58

Quite simply, I have node script that I want to execute once a month.

30 6 1 * * node /home/steve/example/script.js

But this doesn\'t work,

7条回答
  •  借酒劲吻你
    2020-12-02 09:17

    You can also specify paths to binary files on top of your user crontab like:

    PATH=/bin:/usr/bin:/usr/local/bin
    
    * * * * * cd your/path && node foo.js
    * * * * * cd your/path && npm run bar
    

提交回复
热议问题