crontool
Paste a schedule, read it in English, see the next runs.

Restart a PM2 Process with Cron

To restart a PM2-managed Node process on a schedule, call pm2 restart from cron using the absolute path to the pm2 binary and the same user PM2 runs under. For memory leaks, PM2's own max-memory restart is usually better than cron.

The crontab line

Edit the crontab of the user that runs PM2 (crontab -e) and add (4 AM daily):

0 4 * * * /usr/bin/pm2 restart my-app >> /home/user/pm2-restart.log 2>&1

Find the pm2 path

Run which pm2. With nvm it is often under /home/user/.nvm/versions/node/vXX/bin/pm2 — use that full path, because cron's PATH won't include nvm.

Match the PM2 home

PM2 stores state per user in ~/.pm2. If cron runs as a different user it won't see your process list. Add PM2_HOME=/home/user/.pm2 to the crontab if needed.

Better: memory-based restart

For leak recovery, start the app with pm2 start app.js --max-memory-restart 300M so PM2 restarts it automatically. Use cron only for a deliberate scheduled restart.

FAQ

How do I restart a PM2 app with cron?

0 4 * * * /usr/bin/pm2 restart my-app runs at 4 AM. Use the full path to pm2 and the crontab of the user that owns the PM2 process.

Why can't cron find my pm2 process?

PM2 state lives in ~/.pm2 per user. Run cron as the same user, or set PM2_HOME=/home/user/.pm2 in the crontab. Also use the absolute pm2 path (nvm hides it).

Should I restart PM2 on a schedule or on memory?

For leaks use pm2 start --max-memory-restart 300M so PM2 handles it. Use cron only for a purposeful scheduled restart.