如何使用 nodemon 每天自动重启 node.js 脚本?

How to automatically restart a node.js script daily using nodemon?

我正在使用 nodemon 来管理一个 node.js 进程,我希望该进程每 24 小时自动重启一次。有没有一个优雅的解决方案?我也可以创建一个每 24 小时运行一次的 cron 作业,然后执行 kill 但我想要更好的东西 :) 谢谢!

Nodemon 不是管理生产中节点进程的最佳工具。它不会在崩溃的情况下重新启动应用程序,也不会为您提供额外的工具和分析。您可以使用 forever or pm2

pm2 start app.js --cron-restart="0 0 * * *"

Pm2 会在崩溃的情况下自动重启您的应用程序,并且 --cron-restart 它会在给定的 cron 时间重启。

blow 脚本添加到 package.json 文件

"scripts": {
  "test": "echo \"Error: no test specified\" && exit 1",
  "start": "node index.js",
  "dev":"nodemon index.js" 
}

和运行这个命令:

npm run dev