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

后端 未结 7 1564
深忆病人
深忆病人 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:22

    Use absolute paths for the node alias and the file to be run.

    Edit Cron Jobs

    crontab -e
    

    Entry to Run Our Node File

    This will run every minute.

    */1 * * * * * /bin/node /public/test.js
    

    Full Tutorial https://askmacgyver.com/blog/tutorial/how-to-run-node-scripts-from-a-cron-job

提交回复
热议问题