A Nuxt module for cron jobs in your app.
- 👌 19 time presets
- 🕔️ Time zone support
- 🪄️ TypeScript support
- ✨ Auto imports enabled
- ⚡ Zero configuration to start
- 🤝 Nuxt 3/4 support
- 📦 Extendable by Nuxt modules
# Using pnpm pnpm add nuxt-cron -D # Using yarn yarn add nuxt-cron -D # Using npm npm install nuxt-cron -DAdd nuxt-cron to the modules section of nuxt.config.ts
export default defineNuxtConfig({ modules: ['nuxt-cron'] })You can configure the module by adding a nuxt-cron section to your nuxt.config file.
export default defineNuxtConfig({ cron: { runOnInit: true, timeZone: 'Africa/Abidjan', jobsDir: 'cron' } })by default, nuxt-cron will auto-import your cron from the models directory from server directory. You can change this behavior by setting the jobsDir option.
This function creates a new cron job. Example usage:
// server/cron/job.ts import { defineCronHandler } from '#nuxt/cron' export default defineCronHandler('everySecond', () => { console.log('I run every seconds') })or use with params:
// server/cron/job.ts import { defineCronHandler } from '#nuxt/cron' export default defineCronHandler('everySecond', () => { console.log('I run every seconds') }, { runOnInit: true })More examples can be found here.
A huge thank you to everyone who is helping to improve nuxt-cron. Thanks to you, the project can evolve!
To become a contributor, please follow our contributing guide.
This app is open-sourced software licensed under the MIT license.
