node-cron

Node.js cron job scheduling with the `cron` npm package. Use when the user needs to schedule recurring tasks, create cron jobs, validate cron expressions, set up timed callbacks, or work with cron syntax in a Node.js/TypeScript project.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "node-cron" with this command: npx skills add openlark/node-cron

Node Cron

Use the cron npm package (npm install cron) for second-precision scheduled tasks in Node.js.

Triggers

cron job, node-cron, schedule task, cron expression, cron pattern, scheduled job, npm install cron, CronJob, CronTime.

Quick Start

import { CronJob } from 'cron';

const job = new CronJob(
  '0 */5 * * * *',  // every 5 minutes
  () => console.log('Running every 5 minutes'),
  null,             // onComplete
  true,             // start immediately
  'Asia/Shanghai'   // timeZone
);

Or use the object form:

const job = CronJob.from({
  cronTime: '0 0 9 * * 1',    // 9am every Monday
  onTick: () => sendReport(),
  start: true,
  timeZone: 'Asia/Shanghai'
});

job.stop();   // halt
job.start();  // resume

Cron Patterns

The library uses 6 fields (second-precision), unlike standard 5-field Unix cron:

second  minute  hour  day-of-month  month  day-of-week
  0-59   0-59   0-23     1-31       1-12     0-7

Syntax

TokenMeaning
*Any value (every second/minute/etc.)
1,3,5List of values
1-5Range (inclusive)
*/5Every N steps

Names

Use first 3 letters for month/day-of-week (case-insensitive): "jan,mar,dec", "mon,wed,fri"

Day-of-week: 0 or 7 is Sunday.

Common Examples

ExpressionMeaning
*/10 * * * * *Every 10 seconds
0 * * * * *Every minute on the second
0 0 * * * *Every hour
0 0 9 * * *Daily at 9:00 AM
0 30 9 * * 1-59:30 AM Mon-Fri
0 0 0 1 * *Midnight on the 1st of every month

CronJob Class

Constructor Parameters

ParamRequiredDescription
cronTime[OK]Cron pattern string, Date, or Luxon DateTime
onTick[OK]Callback function
onCompleteCalled when job stops via job.stop()
startAuto-start. Default false
timeZoneIANA zone string (e.g. 'Asia/Shanghai')
contextthis context for onTick
runOnInitFire onTick immediately on init
waitForCompletionIf true, skip ticks while callback is still running
errorHandlerCatch exceptions in onTick
nameJob identifier for debugging
thresholdMissed-deadline tolerance in ms. Default 250

Do NOT pass utcOffset together with timeZone -- they conflict.

Key Methods

  • CronJob.from(obj) (static) -- Create with named params
  • job.start() / job.stop() -- Start/stop
  • job.nextDate() -- Next execution as Luxon DateTime
  • job.nextDates(n) -- Array of next N dates
  • job.lastDate() -- Last execution date
  • job.setTime(cronTime) -- Change schedule
  • job.addCallback(fn) -- Add another onTick callback

Read-Only Properties

  • job.isActive -- Whether job is running
  • job.isCallbackRunning -- Whether onTick is currently executing

Standalone Utilities

import * as cron from 'cron';

// When will this cron expression fire next?
const dt = cron.sendAt('0 0 * * *');
console.log(dt.toISO());

// How many ms until next execution?
const ms = cron.timeout('0 0 * * *');

// Validate an expression
const { valid, error } = cron.validateCronExpression('0 0 * * *');

Gotchas

  • Month is 1-12, not 0-11. Upgrade from v2 needs +1 on all month values.
  • Day-of-week 0 = Sunday (7 also works).
  • 6 fields (with seconds) -- unlike standard 5-field Unix cron.
  • Use waitForCompletion: true for async callbacks to prevent overlap.

Async onTick

Wrap async work directly -- waitForCompletion prevents overlapping runs:

const job = CronJob.from({
  cronTime: '*/30 * * * * *',
  onTick: async () => {
    await fetchData();
    await processData();
  },
  waitForCompletion: true,
  start: true
});

Full API Reference

See references/api_reference.md for the complete API documentation including CronTime class, all method signatures, and migration notes.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

崖州区企业服务

崖州区企业服务技能,用于查询企业基本情况、推荐针对性优惠政策、监管企业安全生产、结合崖州区产业发展情况提供企业发展建议等。支持同时为多家企业生成服务报告。触发词:崖州企业、企业服务、优惠政策、安全生产、企业查询、政策推荐、企业监管、发展建议、产业分析。

Registry SourceRecently Updated
General

REDCap CRF Generator

开发者:邹和建、刘从进 REDCap 数据字典生成器 - 将 Word 文档(CRF/方案)转换为 CSV 格式的 REDCap 数据字典。 适用场景: - 用户上传临床试验 CRF/方案 Word 文档,要求生成数据字典 - 将问卷/调查表转换为 REDCap 可导入的 CSV 格式 功能特点: - 智能识别表...

Registry SourceRecently Updated
General

EcoCompute — LLM Energy Efficiency Advisor

Evidence-first, stateless consulting skill for LLM inference energy optimization using measured benchmark priors and anti-pattern detection.

Registry SourceRecently Updated
General

ccf-events

查询 CCF 近期活动、会议和通知。当用户询问 CCF 近期活动、会议通知、即将举办的研讨会、一个月内将举办的会议、刚刚结束的会议等信息时使用此 skill。

Registry SourceRecently Updated