Queue quickstart

Get a first queue working locally with the memory provider.

This quickstart uses the memory provider because it gives you the fastest first success. You do not need a cloud account, extra SDK, or infrastructure to see Queue working end to end.

Install the package

Terminal
pnpm add https://pkg.pr.new/vite-hub/vitehub/@vitehub/queue@main

Configure Queue for local development

You can let ViteHub auto-select Memory in development, but this quickstart keeps the provider explicit so the behavior is obvious.

nuxt.config.ts
export default defineNuxtConfig({
  modules: ['@vitehub/queue/nuxt'],
  queue: {
    provider: 'memory',
  },
})

Define a queue

server/queues/welcome-email.ts
import { defineQueue } from '@vitehub/queue'

export default defineQueue(async (job) => {
  console.log('Queued email:', job.payload.email)

  return {
    sent: true,
  }
})

Send a job

server/api/queues/welcome.post.ts
import { readBody } from 'h3'
import { runQueue } from '@vitehub/queue'

export default defineEventHandler(async (event) => {
  const { email } = await readBody(event)

  return runQueue('welcome-email', {
    email,
  })
})

Verify that it worked

Send one request:

Terminal
curl -X POST http://localhost:3000/api/queues/welcome \
  -H 'content-type: application/json' \
  -d '{"email":"ava@example.com"}'

You should see two success signals:

  • the HTTP response returns immediately with Queue send metadata
  • your server logs Queued email: ava@example.com after the request finishes

That delayed log is the important part. With Memory, runQueue() enqueues the job and the handler runs asynchronously in the same Node.js process.

Next steps