https://github.com/hywax/nuxt-cron
A Nuxt module for cron jobs in your app.
https://github.com/hywax/nuxt-cron
cron node nuxt-module nuxt3 nuxt4 typescript
Last synced: about 1 year ago
JSON representation
A Nuxt module for cron jobs in your app.
- Host: GitHub
- URL: https://github.com/hywax/nuxt-cron
- Owner: hywax
- License: mit
- Created: 2023-11-09T08:19:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-11T19:06:23.000Z (about 1 year ago)
- Last Synced: 2025-04-11T20:24:16.273Z (about 1 year ago)
- Topics: cron, node, nuxt-module, nuxt3, nuxt4, typescript
- Language: TypeScript
- Homepage: https://nuxt-cron.hywax.space
- Size: 3.01 MB
- Stars: 81
- Watchers: 1
- Forks: 4
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://nuxt-cron.hywax.space)
# 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](https://nuxt-cron.hywax.space)
- [🏀 Playground](https://nuxt-cron.hywax.space/playground)
- [✨ Releases](https://github.com/hywax/nuxt-cron/releases)
## Features
- 👌 19 time presets
- 🕔️ Time zone support
- 🪄️ TypeScript support
- ✨ Auto imports enabled
- ⚡ Zero configuration to start
- 🤝 Nuxt 3/4 support
- 📦 Extendable by [Nuxt modules](https://nuxt.com/modules)
## Installation
```bash
# Using pnpm
pnpm add nuxt-cron -D
# Using yarn
yarn add nuxt-cron -D
# Using npm
npm install nuxt-cron -D
```
## Usage
### Setup
Add `nuxt-cron` to the `modules` section of `nuxt.config.ts`
```js
export default defineNuxtConfig({
modules: ['nuxt-cron']
})
```
### Configuration
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
### defineCronHandler
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](https://nuxt-cron.hywax.space/examples/base.html).
## Credits
A huge thank you to everyone who is helping to improve `nuxt-cron`. Thanks to you, the project can evolve!
### Contributors
To become a contributor, please follow our [contributing guide](https://nuxt-cron.hywax.space/community/contributing.html).

## License
This app is open-sourced software licensed under the [MIT license](https://github.com/hywax/nuxt-cron/blob/main/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