Skip to main content
This guide will help you create your first queue and worker with BullMQ. By the end, you’ll have a working example that adds jobs to a queue and processes them.

Prerequisites

Make sure you have:
  • Installed BullMQ (see Installation)
  • Redis running locally or accessible remotely

Basic Example

Let’s build a simple job queue system. We’ll create a queue that processes “paint” jobs.

Configuration Options

Both Queue and Worker accept connection options:
If you don’t specify connection options, BullMQ defaults to localhost:6379.

Listening to Job Events

BullMQ provides two ways to listen to job events:

1. Worker Events (Local)

Events emitted by the worker instance itself:

2. QueueEvents (Global)

Global events that can be listened to from anywhere:
The difference is that Worker events only fire for jobs processed by that specific worker, while QueueEvents fire for all jobs in the queue regardless of which worker processed them.

Adding Job Options

Jobs can be customized with various options:

Reporting Progress

Workers can report progress during job processing:

Complete Working Example

Here’s a complete example in a single file:
example.ts
Run it:

Error Handling

Always add error handlers to prevent crashes:
If you don’t add an error handler, your worker may stop processing jobs when an error occurs. Always add a worker.on('error') listener!

TypeScript Support

BullMQ has full TypeScript support with generics:

Next Steps

Now that you have a working queue, explore more features:

Architecture

Learn how BullMQ works internally

Job Options

Explore delayed jobs, priorities, and more

Worker Concurrency

Process multiple jobs simultaneously

Job Flows

Create complex job dependencies