Cron jobs are time-based scheduling tools used to automate repetitive tasks. By using a specific syntax called a cron expression, you can define the frequency and timing of each task. This helps improve efficiency and ensures that important processes are performed consistently.
Vercel supports cron jobs for Serverless and Edge Functions. This guide will show you how to create your first cron job. Alternatively, you can start from a template.
The following steps will demonstrate how to create a cron job on Vercel that executes every day at 5 am UTC.
First, create a Serverless or Edge Function for your project. The function will be called every time the cron job is triggered.
Go to your vercel.json
file and add the following code:
{ "crons": [ { "path": "/api/cron", "schedule": "0 5 * * *" } ]}
- The
path
must start with/
- The
schedule
property 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
Once your project is deployed on Vercel, our build process will create the cron job. Cron jobs are invoked only for production deployments. Preview deployments are ignored. You can also deploy to your production domain via Git.
Your cron job is now active and will call the /api/cron
path every day at 5:00 am UTC. Learn more about cron jobs.
If you prefer using a different provider for cron jobs, the following services pair well with Vercel: