A Nuxt module for cron jobs in your app.
npm install nuxt-cron
[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![License][license-src]][license-href]
A Nuxt module for cron jobs in your app.
- 📖 Documentation
- 🏀 Playground
- ✨ Releases
- 👌 19 time presets
- 🕔️ Time zone support
- 🪄️ TypeScript support
- ✨ Auto imports enabled
- ⚡ Zero configuration to start
- 🤝 Nuxt 3/4 support
- 📦 Extendable by Nuxt modules
``bashUsing pnpm
pnpm add nuxt-cron -D
Usage
$3
Add
nuxt-cron to the modules section of nuxt.config.ts`js
export default defineNuxtConfig({
modules: ['nuxt-cron']
})
`$3
You can configure the module by adding a
nuxt-cron section to your nuxt.config file.`js
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.API
$3
This function creates a new cron job. Example usage:
`ts
// server/cron/job.ts
import { defineCronHandler } from '#nuxt/cron'export default defineCronHandler('everySecond', () => {
console.log('I run every seconds')
})
`or use with params:
`ts
// 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.
Credits
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.
[npm-version-src]: https://img.shields.io/npm/v/nuxt-cron/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-version-href]: https://npmjs.com/package/nuxt-cron
[npm-downloads-src]: https://img.shields.io/npm/dm/nuxt-cron.svg?style=flat&colorA=18181B&colorB=28CF8D
[npm-downloads-href]: https://npmjs.com/package/nuxt-cron
[license-src]: https://img.shields.io/npm/l/nuxt-cron.svg?style=flat&colorA=18181B&colorB=28CF8D
[license-href]: https://npmjs.com/package/nuxt-cron