Search code examples
node.jsnodemon

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

  • 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.