Nodejs cron plugin vs running nodejs script from crontab

I am creating a tool in which users can enter several items that interest them. Every 24 hours, I want to run a script that checks some JSON responses from external sources for these topics.

My question is: why do you make a script and run it using crontab instead of creating a module using the node-cron plugin and include it in the app.js. Or will you never do that?

Basically, you want to find the best practice on this.

+4
source share
1 answer

The main difference between the two methods, in my opinion, will be the level at which you want to schedule work. When using crontab your jobs are scheduled by cron daemons that run on the system.

node-cron , on the other hand, is a pure implementation of JavaScript cron. Thus, the system is not responsible for the launch of tasks, but your V8 engine that performs it. Tasks will be executed as long as your js application is running.

So why would you use one or the other?

It depends on the purpose of your work, where it is best attached. If the job is maintenance work to start the system through crontab. If you want to run a function in node.js periodically use node -cron. If you want to run a bash script, you want to use crontab. So, how you want to do this through a system (bash) or JavaScript is right for you.

0
source

Source: https://habr.com/ru/post/1485187/


All Articles