Skip to content

Server Mode

Run bunqueue as a standalone server with HTTP and TCP APIs.

Starting the Server

Terminal window
# Default ports (TCP: 6789, HTTP: 6790)
bunqueue
# With custom configuration
bunqueue start \
--tcp-port 6789 \
--http-port 6790 \
--data-path ./data/queue.db
# With authentication
AUTH_TOKENS=secret1,secret2 bunqueue

Environment Variables

VariableDefaultDescription
TCP_PORT6789TCP server port
HTTP_PORT6790HTTP server port
HOST0.0.0.0Server hostname
DATA_PATH(memory)SQLite database path
AUTH_TOKENS(none)Comma-separated auth tokens
CORS_ALLOW_ORIGIN*CORS allowed origins
LOG_FORMATtextLog format (text/json)

Docker

FROM oven/bun:latest
WORKDIR /app
COPY package.json bun.lockb ./
RUN bun install --production
COPY . .
EXPOSE 6789 6790
CMD ["bun", "run", "src/main.ts"]
Terminal window
docker build -t bunqueue .
docker run -p 6789:6789 -p 6790:6790 \
-v ./data:/app/data \
-e DATA_PATH=/app/data/queue.db \
bunqueue

Connecting from Client

When the server is running, clients connect automatically via TCP:

import { Queue, Worker } from 'bunqueue/client';
// No embedded option = TCP mode (connects to localhost:6789)
const queue = new Queue('tasks');
const worker = new Worker('tasks', async (job) => {
console.log('Processing:', job.data);
return { success: true };
});
// Add jobs
await queue.add('my-job', { foo: 'bar' });

Custom Connection

const queue = new Queue('tasks', {
connection: {
host: '192.168.1.100',
port: 6789,
token: 'my-secret-token', // If AUTH_TOKENS is set on server
}
});
const worker = new Worker('tasks', handler, {
connection: {
host: '192.168.1.100',
port: 6789,
token: 'my-secret-token',
}
});

Graceful Shutdown

The server handles SIGINT and SIGTERM:

  1. Stops accepting new connections
  2. Waits for active jobs to complete (30s timeout)
  3. Flushes data to disk
  4. Exits cleanly