To create a cron expression that runs every minute on the 1st and 15th of every month, you can use the cron
package in Node.js.
Here's an example code snippet:
index.tsx254 chars9 lines
In this code snippet, we're creating a new instance of CronJob
with the cron expression 0 * 1,15 * *
. This expression breaks down as follows:
0 *
: This sets the schedule to run every minute on the hour (i.e., at the top of each minute).1,15
: This sets the schedule to run only on the 1st and 15th of every month.* *
: This sets the schedule to run every day of every month, since we don't care about the day of the week.We then define a callback function that will run every time the cron job executes, and start the job by calling start()
on our CronJob
instance.
Note that this example assumes you've installed the cron
package in your Node.js project. To install it, simply run:
index.tsx17 chars2 lines
gistlibby LogSnag