Getting Started
Install
bash
npm install nitro-processorRegister the module in nitro.config.ts (standalone Nitro) or vite.config.ts (Vite + Nitro). See Configuration for full examples, buildDir, and CLI flags.
ts
import { defineConfig } from 'nitro/config'
import nitroProcessor from 'nitro-processor'
export default defineConfig({
modules: [
nitroProcessor({ workers: 'server/workers' }),
],
})Redis
Configure Redis with Nitro runtime config.
- Dev / build:
REDIS_*in.env— see Redis configuration. - Production / Docker:
NITRO_REDIS_*at runtime — Nitro applies env overrides with theNITRO_prefix.
ini
# .env (nitro dev / nitro build)
REDIS_URL=redis://127.0.0.1:6379/0yaml
# Docker — same NITRO_REDIS_* on app and workers services
environment:
NITRO_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 Nitro app normally. This module generates a dedicated workers entry.
- In development, run workers from the Nitro dev workers entry in a separate terminal:
bash
nitro dev
npx nitro-processor devBy default all workers run. To run only specific workers, use the --workers= flag with a comma-separated list of worker names:
bash
npx nitro-processor dev --workers=basic,helloCLI
Use the CLI to run workers with file watching and restarts:
bash
# runs all workers
npx nitro-processor dev
# run only specific workers
npx nitro-processor dev --workers=basic,helloNotes:
- Dev workers entry default:
node_modules/.nitro/dev/workers/index.mjs. CustombuildDirinnitro.config.tsorvite.config.ts? Use--buildDirorNITRO_PROCESSOR_BUILD_DIR— see Configuration. - If the dev workers entry does not exist yet, the CLI will ask you to start your Nitro dev server first and exit.
- If your
package.jsondoes not have aprocessor:devscript, the CLI will offer to add:
json
{
"scripts": {
"processor:dev": "nitro-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:
bash
nitro build
NITRO_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,helloDurabull
See the dedicated page: Durabull