Skip to content

Monque

Type-safe, reliable job scheduling powered by MongoDB
import { Monque } from '@monque/core';
import { MongoClient } from 'mongodb';

// Connect to MongoDB
const client = new MongoClient('mongodb://localhost:27017');
await client.connect();
const db = client.db('myapp');

// Create scheduler instance
const monque = new Monque(db);
await monque.initialize();

// Define your job data type
interface EmailJob {
  to: string;
  subject: string;
  body: string;
}

// Register a worker with type safety
monque.register<EmailJob>('send-email', async (job) => {
  console.log(`Sending email to ${job.data.to}`);
  await sendEmail(job.data.to, job.data.subject, job.data.body);
});

// Monitor job lifecycle
monque.on('job:complete', ({ job, duration }) => {
  console.log(`Job ${job.name} completed in ${duration}ms`);
});

// Start processing
monque.start();

// Enqueue a job - it's that simple!
await monque.enqueue('send-email', {
  to: 'user@example.com',
  subject: 'Welcome!',
  body: 'Thanks for signing up.'
});
bun add @monque/core mongodb

Atomic Locking

Prevents concurrent duplicate processing across multiple schedulers using MongoDB atomic claims. Jobs can still be retried or re-run after crashes, so workers should be idempotent.

Heartbeat Monitoring

Detects stale jobs from crashed workers and recovers them automatically to keep processing moving.

Type-Safe

Full TypeScript support with generics for job payloads. Catch errors at compile time, not runtime.

Framework Agnostic

Works with any Node.js framework and runs wherever you can connect to MongoDB.

Event-Driven

Subscribe to job lifecycle events for full observability and integration with your logging infrastructure.

Change Streams

Real-time job notifications via MongoDB Change Streams, while polling continues as a safety net.

Cron Scheduling

Schedule recurring jobs with standard 5-field cron expressions. Automatic rescheduling after successful completion.

Exponential Backoff

Automatic retries with configurable exponential backoff. Failed jobs retry intelligently without overwhelming your system.

Installation Guide

Learn about prerequisites and detailed setup instructions. Read more →

Quick Start Tutorial

Build your first job queue in under 5 minutes. Get started →

Core Concepts

Understand jobs, workers, and the processing lifecycle. Learn more →

API Reference

Complete API documentation with TypeScript types. Explore →

Monque stands on the shoulders of giants. We’ve drawn inspiration and concepts from these excellent libraries: