Quick Start — Node.js
Job definitions and client creation are identical to Next.js — just import from @queuebase/node instead of @queuebase/nextjs.
1. Install
Section titled “1. Install”npm install @queuebase/node zod2. Define jobs
Section titled “2. Define jobs”import { createJobRouter, job } from "@queuebase/node";import { z } from "zod";
export const jobs = createJobRouter({ sendEmail: job({ input: z.object({ to: z.string().email(), subject: z.string(), body: z.string(), }), handler: async ({ input, jobId, attempt }) => { // your logic here return { sent: true }; }, defaults: { retries: 3, backoff: "exponential", }, }),});
export type JobRouter = typeof jobs;3. Create a client
Section titled “3. Create a client”import { createClient } from "@queuebase/node";import { jobs } from "./index";
export const jobClient = createClient(jobs, { apiUrl: process.env.QUEUEBASE_API_URL ?? "http://localhost:3847", apiKey: process.env.QUEUEBASE_API_KEY, callbackUrl: process.env.QUEUEBASE_CALLBACK_URL ?? "http://localhost:3000/api/queuebase",});4. Create the webhook handler
Section titled “4. Create the webhook handler”createNodeHandler works with Node’s http.IncomingMessage/ServerResponse:
import { createNodeHandler } from "@queuebase/node";import { jobs } from "./jobs";
const handler = createNodeHandler(jobs);Express
Section titled “Express”import express from "express";import { createNodeHandler } from "@queuebase/node";import { jobs } from "./jobs";
const app = express();const handler = createNodeHandler(jobs);
// Use express.raw() so the body isn't pre-parsed as JSONapp.post("/api/queuebase", express.raw({ type: "*/*" }), (req, res) => { handler(req, res);});Fastify
Section titled “Fastify”import Fastify from "fastify";import { createNodeHandler } from "@queuebase/node";import { jobs } from "./jobs";
const fastify = Fastify();const handler = createNodeHandler(jobs);
fastify.post("/api/queuebase", (req, reply) => { handler(req.raw, reply.raw);});5. Enqueue a job
Section titled “5. Enqueue a job”import { jobClient } from "./jobs/client";
const { jobId, getStatus } = await jobClient.sendEmail.enqueue({ to: "user@example.com", subject: "Welcome", body: "Hello!",});6. Run the dev server
Section titled “6. Run the dev server”npx queuebase devStart your app in another terminal and you’re ready to go.