Cron Jobs
Schedule automated tasks in your ShipAhead app with cron jobs. Follow the guide to configure recurring work such as reminders and other background tasks.
Tools
- cron-job.org: External service to schedule jobs by calling your API endpoints.
Setup & Run Cron Jobs
- Set CRON_SECRET
- Add an environment variable to secure your cron endpoints:
.env
CRON_SECRET="your-secret-key" - Use any strong key you like or generate one with a password generator.
- Add an environment variable to secure your cron endpoints:
- Add a Cron Job
- Create a file in
/server/jobs/, e.g.,sendReminderEmails.ts:server/jobs/sendReminderEmails.tsexport async function sendReminderEmails() { console.log('[CRON] Running job...'); // Add your logic (DB updates, notifications, etc.) } - Register it in
server/jobs/list.ts:server/jobs/list.tsimport { sendReminderEmails } from './sendReminderEmails'; const JOBS: any = { sendReminderEmails }; export function getJobModules(name: string) { return JOBS[name] ?? null; }
- Create a file in
- Schedule the Job
- Trigger your job via the API endpoint:
https://your-site.com/api/cron/sendReminderEmails - Create a cron-job.org task:
- URL: same as above
- Execution schedule: e.g.,
0 8 * * *(runs daily at 8 AM) - HTTP Header:
X-Cron-Secret: your-secret-key
- Trigger your job via the API endpoint:
- Verify
- Check server logs for
[CRON]messages. - Or test endpoint directly with curl:
curl -H "X-Cron-Secret: your-secret-key" https://your-site.com/api/cron/sendReminderEmails
- Check server logs for
Why Use cron-job.org?
- No need to install
node-cronor run background workers. - Works with serverless platforms like Vercel, Netlify, or Cloudflare.
- Secure with your custom
X-Cron-Secret. - Easy to schedule and manage without touching your app’s main code.
Example: Adding a New Job
- Just create a new file in
/server/jobs/, register it inlist.ts, and schedule it on cron-job.org like above. - You can add unlimited jobs following the same pattern.
Documentation
Create and organize documentation with Nuxt Content in your ShipAhead app. Learn how to manage Markdown pages, navigation, language support, and SEO.
Error Handling
Set up friendly error pages for 404 and 500 errors in your Nuxt app. Learn how ShipAhead handles errors and how to customize messages for your users.