Getting Started
Learn how to get started with Duron, a powerful job queue system for Node.js and Bun.js
Duron is a powerful, type-safe job queue system built for Node.js and Bun.js. It provides a robust way to manage background jobs, handle concurrency, retries, and more.
Upgrading from an earlier version? Read Upgrading first.
Installation
Install Duron using your preferred package manager:
# Using npm
npm install duron drizzle-orm@1.0.0-rc.6 @opentelemetry/api
# Using pnpm
pnpm add duron drizzle-orm@1.0.0-rc.6 @opentelemetry/api
# Using yarn
yarn add duron drizzle-orm@1.0.0-rc.6 @opentelemetry/api
# Using bun
bun add duron drizzle-orm@1.0.0-rc.6 @opentelemetry/apiDuron is tested with drizzle-orm 1.0.0-rc.6 and postgres 4.2.0. Install that exact drizzle-orm version: Duron's peer range is 1.0.0-rc.6 || ^1.0.0, and a later release candidate (such as drizzle-orm@rc once rc.7 ships) does not satisfy it. drizzle-orm 1.0 is ESM-only, so on Node.js use version ^20.19.0 or >=22.12.0.
@opentelemetry/api (^1.9.0) is a peer dependency: Duron uses only the OpenTelemetry API, and your application chooses the SDK. See Telemetry.
Duron is tested with PostgreSQL 16 and 19.
Install the driver of your database. For PostgreSQL, install postgres.js (^4.1.1):
# Using npm
npm install postgres
# Using pnpm
pnpm add postgres
# Using yarn
yarn add postgres
# Using bun
bun add postgresFor PGlite (an embedded PostgreSQL for development and tests), install @electric-sql/pglite (^0.5.17 || ^0.6.0):
# Using npm
npm install @electric-sql/pglite@0.6
# Using pnpm
pnpm add @electric-sql/pglite@0.6
# Using yarn
yarn add @electric-sql/pglite@0.6
# Using bun
bun add @electric-sql/pglite@0.6Duron is tested with PGlite 0.6.1 (PostgreSQL 19). PGlite 0.5.17 or later 0.5.x (PostgreSQL 18) is also supported: the PGlite test suite passes with 0.5.17, run manually (CI runs 0.6.1 only). A persistent PGlite data directory only opens with the PostgreSQL major version that created it: PGlite 0.6 cannot open a directory created by PGlite 0.5, so keep 0.5 for an existing directory or dump and restore its data.
Schema Library
Duron uses Standard Schema for input/output validation. You'll need a schema library that implements this specification:
# Zod (recommended)
bun add zod
# Or Valibot
bun add valibot
# Or ArkType
bun add arktypeQuick Start
Here's a simple example to get you started:
import { duron } from 'duron'
import { defineAction } from 'duron/action'
import { pgliteAdapter } from 'duron/adapters/pglite'
import { z } from 'zod'
// Define an action
const sendEmail = defineAction()({
name: 'sendEmail',
input: z.object({
to: z.string().email(),
subject: z.string(),
body: z.string(),
}),
output: z.object({
success: z.boolean(),
}),
handler: async (ctx) => {
const { to, subject, body } = ctx.input
// Use steps to break down work into retryable units
const result = await ctx.step('sendEmail', async ({ signal }) => {
// Your email sending logic here
// The signal can be used to handle cancellation
console.log(`Sending email to ${to}`)
// Simulate API call
const response = await fetch('https://api.email.com/send', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ to, subject, body }),
signal, // Pass signal to enable cancellation
})
if (!response.ok) {
throw new Error('Failed to send email')
}
return await response.json()
})
return {
success: result.success ?? true,
}
},
})
// Create a Duron client
const client = duron({
database: pgliteAdapter({
connection: ':memory:',
}),
actions: {
sendEmail,
},
logger: 'info',
})
// Start the client
await client.start()
// Run an action
const jobId = await client.runAction('sendEmail', {
to: 'user@example.com',
subject: 'Hello',
body: 'This is a test email',
})
console.log(`Job created with ID: ${jobId}`)
// On shutdown: running jobs that do not finish return to the queue
await client.stop()What's Next?
- Learn about Actions - the building blocks of Duron
- Understand Jobs and Steps - how work is organized
- Explore Adapters - database backends
- Add Telemetry - observability for your job queue
- Check out Examples - real-world use cases