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

I'm using nodemon to manage a node.js process, and I would that process to auto-restart every 24h. Is there an elegant solution for this? I could also just create a cron job that runs every 24h and just do a kill but I wanted something nicer :) thanks!



Solution 1:[1]

Nodemon isn't the best tool to manage the node processes in production. It will not restart the app in case of a crash or provide you additional tools and analytics. You can user forever or pm2

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

Pm2 will auto restart your app in case of a crash and with --cron-restart it will restart at a given cron time.

Solution 2:[2]

blow script add yo package.json file

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

and run this command:

npm run dev

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ridham Tarpara
Solution 2 Nafiz Bayrak