Getting Started
Upgrading from 0.x or 1.x
If you used processor.redis, $workers(), or setConnection(), read Upgrading first.
Install
bash
npx nuxi@latest module add nuxt-processor@latestAdd the module in nuxt.config.ts:
ts
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['nuxt-processor'],
})Redis
Configure Redis with runtime config.
- Dev / build:
REDIS_*in.env(loaded bynuxi dev/nuxi build) — see Redis configuration. - Production / Docker:
NUXT_REDIS_*at runtime — Nuxt only applies env overrides with theNUXT_prefix. After build, the .env file is not read in production; set vars on the container (Composeenvironment:, K8s, etc.).
ini
# .env (nuxi dev / nuxi build)
REDIS_URL=redis://127.0.0.1:6379/0yaml
# Docker — same NUXT_REDIS_* on app and workers services
environment:
NUXT_REDIS_URL: redis://redis:6379/0Full reference: Redis configuration · API.
Define a queue and enqueue from your app
Create server/queues/index.ts:
ts
import { defineQueue } from '#processor'
export default defineQueue({
name: 'hello',
})Define a worker
Create server/workers/index.ts:
ts
import { defineWorker } from '#processor'
import type { Job } from '#bullmq'
export default defineWorker({
name: 'hello',
async processor(job: Job) {
console.log('processed', job.name, job.data)
return job.data
},
options: {},
})Running
- Start your Nuxt app normally. This module generates a dedicated workers entry.
- In development, run workers from
.nuxt/dev/workers/index.mjsin a separate terminal:
bash
nuxi dev
node .nuxt/dev/workers/index.mjsBy default all workers run. To run only specific workers, use the --workers= flag with a comma-separated list of worker names:
bash
node .nuxt/dev/workers/index.mjs --workers=basic,helloCLI
Use the CLI to run workers with file watching and restarts:
bash
# runs all workers
npx nuxt-processor dev
# run only specific workers
npx nuxt-processor dev --workers=basic,helloNotes:
- If
.nuxt/dev/workers/index.mjsdoes not exist yet, the CLI will ask you to start your Nuxt dev server first and exit. - If your
package.jsondoes not have aprocessor:devscript, the CLI will offer to add:
json
{
"scripts": {
"processor:dev": "nuxt-processor dev"
}
}Then you can run:
bash
npm run processor:dev- After building for production, run workers with the same Redis env as your app. On Docker deploys, use
NUXT_REDIS_*on both containers (Nuxt production env); locally you can rely onREDIS_*baked in at build if you set them duringnuxi build:
bash
nuxi build
NUXT_REDIS_URL=redis://127.0.0.1:6379/0 node .output/server/workers/index.mjsTo run only specific workers in production:
bash
node .output/server/workers/index.mjs --workers=basic,helloBull Board
See the dedicated page: Bull Board