node-red-contrib-fff-cron-task 1.0.0

A Node-RED node to schedule tasks using cron strings or dates.

npm install node-red-contrib-fff-cron-task

node-red-contrib-fff-cron-task

npm version CI License: ISC

A Node-RED node to schedule one-shot or recurring tasks using a Date or a cron expression. Supports multiple independent jobs in one node and optional persistence across restarts.

Install

cd ~/.node-red
npm install node-red-contrib-fff-cron-task

On Windows replace the first line with cd %HOMEPATH%\.node-red.

After restarting Node-RED, drag cron-task from the function category onto your flow.

Quick start

Wire an inject (or function) node in front and set one of:

// recurring
msg.cron = "*/5 * * * *";   // every 5 minutes

// or one-shot
msg.date = new Date(Date.now() + 60_000); // one minute from now

Output 1 fires when the schedule triggers. Output 2 emits errors.

A ready-to-import example flow is available at examples/basic-flow.json.

Configuration

Field Type Default Description
name string "" Label shown in the editor
persistent boolean false Survive restarts/redeploys (see Persistence)

Inputs

Property Type Description
msg.cron string Cron expression (5 or 6 fields). Validated strictly.
msg.date Date | string One-shot execution time. Must be in the future.
msg.inputDate string | Date Legacy field — auto-detects cron vs date. Kept for backward compatibility.
msg.job_id string Optional. Defaults to "default". Lets you run multiple jobs in one node.
msg.action string Control command. See below.

Priority when more than one schedule input is set: msg.cron > msg.date > msg.inputDate.

Control commands (msg.action)

Value Effect
"cancel" Stops the job referenced by msg.job_id (or "default" if omitted).
"cancelAll" Stops every active job in this node instance.
"list" Emits the current job list on output 1 as { payload: "jobs", jobs: [...] }. Schedules nothing.

Outputs

Output 1 — Triggered events and list responses

When a schedule fires:

{
  payload: "triggered",
  original_payload: "...",      // what you scheduled
  job_id: "default",
  timestamp: 1748000000000,
  nextInvocation: "2026-05-22T14:35:00.000Z" // null for one-shot dates after they fire
}

When you send msg.action="list":

{
  payload: "jobs",
  jobs: [
    { job_id: "a", schedule: "*/5 * * * *",       type: "cron", nextInvocation: "2026-05-22T14:35:00.000Z" },
    { job_id: "b", schedule: "2026-12-25T10:00:00", type: "date", nextInvocation: "2026-12-25T10:00:00.000Z" }
  ],
  timestamp: 1748000000000
}

Output 2 — Errors

{
  payload: "Invalid cron string: foo",
  error: {
    type: "InvalidCron", // MissingInput | InvalidCron | InvalidDate | PastDate | ScheduleFailed | ScheduleError
    input: "foo"
  }
}

Persistence

When Persistent is on, jobs are saved to the node context under the key scheduled_jobs and restored automatically.

Important — context backend matters. Node-RED stores context in memory by default, so jobs are lost on a real process restart even with persistence enabled. To survive restarts, configure a filesystem store in settings.js:

contextStorage: {
  default: { module: "localfilesystem" }
}

Without it, "persistent" only survives redeploys (not process restarts).

Cron syntax

Standard 5 or 6-field cron, validated by cron-parser:

*    *    *    *    *    *
|    |    |    |    |    |
|    |    |    |    |    +-- day of week (0-7, 0 and 7 are Sun)
|    |    |    |    +------- month (1-12)
|    |    |    +------------ day of month (1-31)
|    |    +----------------- hour (0-23)
|    +---------------------- minute (0-59)
+--------------------------- second (0-59, optional)

Examples:

  • 0 0 * * * — daily at midnight
  • 0 */6 * * * — every 6 hours
  • */30 * * * * * — every 30 seconds (6-field form)
  • 0 0 1 * * — first day of every month at midnight

Troubleshooting

  • Job disappears after restart even with persistent: true — your context store is in-memory. See Persistence.
  • Cron rejectedcron-parser is strict. Test your expression at crontab.guru first.
  • Two schedules clash inside one node — pass distinct msg.job_id values to keep them independent. Reusing the same id replaces the previous job.

Testing

npm test
npm run lint

Contributing

See CONTRIBUTING.md. Bug reports and PRs welcome — please add tests for behavioral changes.

License

ISC — Carlos Fontán.

Node Info

Version: 1.0.0
Updated 17 hours ago
License: ISC
Rating: not yet rated

Categories

Actions

Rate:

Downloads

11 in the last week

Nodes

  • fff-cron-task

Keywords

  • node-red
  • node-red-contrib
  • cron
  • schedule
  • timer
  • persistent
  • fff

Maintainers