Registry / devops / better-queue

better-queue

JSON →
library3.8.12jsnpmunverified

Simple-to-use yet powerful queue for Node.js with support for persistent storage, batched processing, priority, task merging, retry on fail, concurrent processing, progress events, and task statistics. Current stable version is 3.8.12. The library is mature and stable with infrequent releases. It differentiates itself through its extensive feature set including fine-tuned timing controls, ETA progress, and extendable storage backends like SQLite and Redis, while remaining easy to set up.

npm install better-queue
INSTALL
IMPORT
SIG · BETTER-QUEUE
B
better-queue
devopsjavascriptv3.8.12
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Queue
import Queue from 'better-queue'
const { Queue } = require('better-queue')
Default export is the Queue class. Use ESM import or CommonJS require() as shown.
Queue (CommonJS)
const Queue = require('better-queue')
const { default: Queue } = require('better-queue')
For Node.js with CommonJS, use require(). Named exports are not used.
Queue events
const q = new Queue(fn); q.on('task_finish', handler)
Events are emitted on the queue instance. Common events: task_finish, task_failed, empty, drain.

Creates a queue that processes tasks by doubling the input, using events to capture results and drain.

const Queue = require('better-queue'); const q = new Queue(function (input, cb) { // Simulate async processing const result = input * 2; setTimeout(() => cb(null, result), 100); }); // Push tasks and handle results via events q.on('task_finish', function (taskId, result, stats) { console.log(`Task ${taskId} finished with result ${result}, took ${stats.elapsed}ms`); }); q.on('drain', function () { console.log('All tasks completed.'); }); q.push(1); q.push(2); q.push(3);
Debug
Known issues
gotchaTask ID is derived from task.id by default; if task.id is not a string, a random ID is generated. This can lead to unexpected merging behavior if tasks have numeric IDs or if the id property is missing.
fix
Set the `id` option explicitly to a string property or function that returns a string.
affects: >=3.0.0
gotchaErrors passed to the worker callback must be an Error instance; passing a string or null may cause issues.
fix
Always pass an Error object: cb(new Error('message')).
affects: >=3.0.0
deprecatedThe `maxRetries` option has been deprecated in favor of `retry.maxRetries`.
fix
Use `retry: { maxRetries: 3 }` instead of `maxRetries: 3`.
affects: >=3.8.0
Errors
Common errors & fixes
TypeError: cb is not a function
Worker function does not accept a callback or the callback is not called.
fix
Ensure your worker function takes (input, cb) and calls cb(null, result) for success or cb(err) for failure.
Error: Cannot find module 'better-queue'
Package not installed or not in node_modules.
fix
Run `npm install better-queue` in your project directory.
Upgrade
Version history
3.8.12latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
better-queue — npm install better-queue · libregistry