nuxt-cron
TypeScript icon, indicating that this package has built-in type declarations

1.5.1 • Public • Published

nuxt-cron

Nuxt Cron

npm version npm downloads License

A Nuxt module for cron jobs in your app.

Features

  • 👌  19 time presets
  • 🕔️  Time zone support
  • 🪄️  TypeScript support
  • ✨  Auto imports enabled
  • ⚡  Zero configuration to start
  • 📦  Extendable by Nuxt modules

Installation

# 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

export default defineNuxtConfig({
  modules: ['nuxt-cron']
})

Configuration

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.

API

defineCronHandler

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.

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.

nuxt-cron

License

This app is open-sourced software licensed under the MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i nuxt-cron

Weekly Downloads

214

Version

1.5.1

License

MIT

Unpacked Size

17.9 kB

Total Files

17

Last publish

Collaborators

  • hywax