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

1

Create an API route

Create an API endpoint for your scheduled task

Code
// 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.
}
2

Secure your endpoint

Add authentication to prevent unauthorized access

Code
// .env.local
CRON_SECRET=your-secret-token-here
3

Set up external scheduler

Use CronUptime or similar to call your endpoint

Code
# Configure in CronUptime:
# URL: https://yourapp.vercel.app/api/scheduled-task
# Headers: { "Authorization": "Bearer your-secret-token" }
# Schedule: Every 5 minutes

Next.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

No, Next.js doesn't have native cron support. You can use Vercel's cron feature (Pro plan), an external scheduler service, or deploy to a server with system cron.
Create an API route for your task and use an external service to call it on schedule. For long-running jobs, consider using a queue service like Inngest or Trigger.dev.
node-cron doesn't work well with serverless Next.js deployments because the process doesn't stay alive. It only works for self-hosted Next.js with a persistent Node.js process.

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.

The URL that will be called. You can also paste a curl command here.

Runs for 7 daysSign in for permanent