Next.js Cron Jobs
Next.js doesn't have built-in cron functionality, but you can implement scheduled tasks using API routes combined with external schedulers or Vercel's cron feature.
How to Set Up Cron Jobs in Next.js
Create an API route
Create an API endpoint for your scheduled task
// app/api/scheduled-task/route.ts
import { NextResponse } from 'next/server';
export async function GET(request: Request) {
// Verify the request is from your cron service
const authHeader = request.headers.get('authorization');
if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
// Your task logic here
await performScheduledTask();
return NextResponse.json({ success: true });
}
async function performScheduledTask() {
// Database cleanup, email sending, etc.
}Secure your endpoint
Add authentication to prevent unauthorized access
// .env.local
CRON_SECRET=your-secret-token-hereSet up external scheduler
Use CronUptime or similar to call your endpoint
# Configure in CronUptime:
# URL: https://yourapp.vercel.app/api/scheduled-task
# Headers: { "Authorization": "Bearer your-secret-token" }
# Schedule: Every 5 minutesNext.js Cron Limitations vs CronUptime
Next.js Limitations
- •No native cron support in Next.js
- •Vercel cron requires Pro plan
- •Serverless functions have timeout limits
- •Need external service for free hosting
- •Must handle authentication manually
CronUptime Advantages
- ✓Works with any Next.js deployment (Vercel, Netlify, self-hosted)
- ✓Free tier available
- ✓Built-in execution monitoring
- ✓Supports custom headers for authentication
- ✓Simple setup - just paste your URL
Why Use CronUptime Instead?
While Next.js cron jobs work for basic use cases, managing infrastructure for scheduled tasks adds complexity. CronUptime offers a simpler, serverless alternative.
No Infrastructure
We handle execution. No servers to maintain.
Reliable Timing
Built on Cloudflare for 99.9%+ uptime.
Any Endpoint
Works with any HTTP endpoint on any platform.
Frequently Asked Questions
Quick Reference
Cron Expression:
*/5 * * * *Human Readable:
every 5 minutes
Cron Jobs on Other Platforms
Try CronUptime Free
Schedule HTTP requests without managing Next.js infrastructure.
Try it now - Free
Create a cron job running every 5 minutes. No sign-up required.