Task scheduling enables you to schedule arbitrary code to be executed at a fixed date and time, at recurring intervals, or once after a specified interval.

No developer wants to spend all their time on tedious tasks such as system maintenance and administration, daily database backup, and downloading files and emails at regular intervals. You’d much rather focus on productive tasks instead of keeping track of when these bothersome chores need to get done. And you’d certainly rather be asleep in your bed than up at some ungodly hour, staring bleary-eyed at a monitor as you run tasks that are best executed when server resources are being consumed at a lower rate.

That’s where task scheduling comes in.

Task scheduling enables you to schedule arbitrary code (methods/functions) and commands to be executed at a fixed date and time, at recurring intervals, or once after a specified interval. In Linux operating systems, task scheduling is often handled by utility services such as cron at the OS level. For Node.js apps, cron-like functionalities are implemented using packages such as node-cron, which bills itself as a “tiny task scheduler in pure JavaScript for NodeJs.”

The actions of cron are driven by a crontab (cron table) file, a configuration file that contains instructions to the cron daemon. The node-cron module allows you to schedule tasks in Node using the full crontab syntax.

A crontab syntax looks like this:

 ## ┌────────────── second (optional)
 ## │ ┌──────────── minute
 ## │ │ ┌────────── hour
 ## │ │ │ ┌──────── day of month
 ## │ │ │ │ ┌────── month
 ## │ │ │ │ │ ┌──── day of week
 ## │ │ │ │ │ │
 ## │ │ │ │ │ │
 ## * * * * * *

#node #javascript #developer

Scheduling tasks in Node.js using node-cron
2.10 GEEK