CRON Jobs
Automate and manage recurring tasks in your VitNode app with cron jobs — perfect for cleanups, emails, reports, and more.
Adapters
Before you can use cron functionality, you need to provide an adapter to your application.
REST API
Run cron jobs by triggering REST API endpoints from an external scheduler.
Node CRON
In-memory tiny task scheduler in pure JavaScript for node.js based on GNU crontab.
Usage
Create CRON file
import { buildCron } from "@vitnode/core/api/lib/cron";
export const cleanCron = buildCron({
name: "clean",
description: "Clean up expired sessions and tokens",
// Run every 1 hour
schedule: "0 * * * *",
handler: async c => {
console.log("Running cleanup cron job...");
},
});Register CRON in module
import { buildModule } from "@vitnode/core/api/lib/module";
import { CONFIG_PLUGIN } from "@/config";
import { cleanCron } from "./cron/clean.cron";
export const cronModule = buildModule({
pluginId: CONFIG_PLUGIN.pluginId,
name: "clean",
routes: [],
cronJobs: [cleanCron],
});Check Your Cron Job
When your CRON job will run first time, you should see your job in AdminCP under Core => Advanced => Cron Jobs.