Question

Getting issue when i set cron using node-cron and pm2 but after 1 day my crons not working and also my droplets terminal getting slow issue

Hello Team, I am getting issue after following below mentioned tutorial for set node crons when i set cron and run my index.js file with node command it run properly and crons working fine but issue is as usual when i close the terminal cron is stops working so solution is to use pm2 i used pm2 and start my index.js file and its working fine but after 1 or 2 days my droplet getting slowness issue and not working well i need to restart that and after restart again its working fine for two days and then getting same issue. If anyone have solution for this please let me know i am struggling to finding the way to do this.

I used this tutorial to set my cron application https://www.digitalocean.com/community/tutorials/nodejs-cron-jobs-by-examples


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
February 29, 2024

Heya @info3dbe0e42d43bca7d89b055447b,

So, PM2 is the proper choice for a continuous execution of your NodeJS App.

As for the slowness you are experiencing after a while, check your droplet’s processes, see if you have anything stuck that is running for the last two days.

You can do that with top, htop or by running

ps aux

Additionally, check your memory, see if you have any available.

My best best is that your app is leaving some processes unclosed or there are just stuck processes for days. See if that is the case.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel