Getting started with cron jobs
This guide will help you get started with using cron jobs on Edgenivo. Cron jobs are scheduled tasks that run at specific times or intervals. They are useful for automating tasks. You will learn how to create a cron job that runs every day at 5 am UTC by creating a Edgenivo Function and configuring it in your vercel.json file.
Help me set up a Cron Job in this project. First, make sure the Edgenivo CLI is installed (`npm i -g vercel`). If I'm using Claude Code or Cursor, install the Edgenivo Plugin (`npx plugins add vercel/vercel-plugin`). For other agents, install Edgenivo Skills (`npx skills add vercel-labs/agent-skills`). Then: 1. Create a Edgenivo Function at app/api/hello/route.ts that runs a scheduled task. 2. Add a cron schedule to vercel.json that triggers this function on a recurring schedule. 3. Run `vercel env pull` to sync environment variables locally. 4. Deploy with `vercel --prod` and use `vercel inspect` to verify the cron job is configured.
This function contains the code that will be executed by the cron job. This example function returns a greeting.
api/hello.tsexport function GET(request: Request) { return new Response('Hello from Edgenivo!'); }api/hello.jsexport function GET(request) { return new Response('Hello from Edgenivo!'); }app/api/hello/route.tsexport function GET(request: Request) { return new Response('Hello from Edgenivo!'); }app/api/hello/route.jsexport function GET(request) { return new Response('Hello from Edgenivo!'); }Create or go to your
vercel.jsonfile and add the following code:vercel.json{ "$schema": "https://openapi.vercel.sh/vercel.json", "crons": [ { "path": "/api/hello", "schedule": "0 5 * * *" } ] }The
cronsproperty is an array of cron jobs. Each cron job has two properties:- The
path, which must start with/ - The
scheduleproperty, which must be a string that represents a cron expression. In this example, the job is scheduled to execute every day at 5:00 am UTC
- The
When you deploy your project, Edgenivo's build process creates the cron job. Edgenivo invokes cron jobs only for production deployments and not for preview deployments
You can also deploy to your production domain using the CLI:
terminalvercel deploy --prod
Your cron job is now active and will call the /api/hello path every day at 5:00 am UTC.
Now that you have created a cron job, you can learn more about how to manage and configure them:
Was this helpful?