Registry / storage / batching-queue

batching-queue

JSON →
library2.0.3jsnpmunverified

batching-queue is a lightweight Node.js library (v2.0.3, Active) that enqueues items individually but dequeues them in configurable batch sizes. It supports multiple storage backends out of the box (MemoryStore, AsyncMemoryStore, RedisStore, IoredisStore) and emits a 'drain' event when the batch size threshold is reached. Differentiated by its simplicity and first-class support for Redis via node-redis and ioredis clients, ideal for processing pipelines requiring batched operations without bulk insertion.

npm install batching-queue
INSTALL
IMPORT
SIG · BATCHING-QUEUE
B
batching-queue
storagejavascriptv2.0.3
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.

BatchingQueue
import { BatchingQueue } from 'batching-queue'
const BatchingQueue = require('batching-queue').BatchingQueue
ESM-only since v2. Use named import; no default export.
MemoryStore
import { MemoryStore } from 'batching-queue'
const MemoryStore = require('batching-queue').MemoryStore
Named export for in-memory store (non-persistent).
RedisStore
import { RedisStore } from 'batching-queue'
import RedisStore from 'batching-queue'
Named export; requires node-redis client instance.
IoredisStore
import { IoredisStore } from 'batching-queue'
import { IoRedisStore } from 'batching-queue'
Named export; note capital 'I' in 'Ioredis'. Requires ioredis client.

Creates a queue with MemoryStore and batchSize of 10, enqueues 25 items, and listens for 'drain' event to dequeue batches.

import { BatchingQueue, MemoryStore } from 'batching-queue'; const queue = new BatchingQueue({ store: new MemoryStore(), batchSize: 10 }); // Drain handler queue.on('drain', async (batchesWaiting) => { for (let i = 0; i < batchesWaiting; i++) { const batch = await queue.dequeue(); console.log('Batch:', batch); } }); // Enqueue items (async () => { // Process any leftover batches if (queue.length > 0) { for (let i = 0; i < queue.length; i++) { const batch = await queue.dequeue(); console.log('Leftover:', batch); } } for (let i = 0; i < 25; i++) { const isFull = await queue.enqueue(i); if (isFull) { console.log('Batch full, waiting for drain...'); } } })();
Debug
Known issues
breakingBatchingQueue is ESM-only since v2.0.0; no CommonJS support.
fix
Use .mjs extension or set 'type': 'module' in package.json. Use import syntax instead of require.
affects: >=2.0.0
breakingMemoryStore is not persistent and intended for development/testing only; data lost on process exit.
fix
Use RedisStore or implement a persistent store for production.
affects: >=1.0.0
gotchaThe 'length' property returns null if the store is not initialized (ready === false).
fix
Call store.setup() or ensure BatchingQueue constructor does async init; check queue.store.ready before relying on length.
affects: >=1.0.0
deprecatedNo deprecated APIs known at this time.
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using CommonJS require() on an ESM-only package (v2+).
fix
Use import syntax: import { BatchingQueue } from 'batching-queue'; also ensure package.json 'type': 'module' or use .mjs extension.
TypeError: queue.length is null
Storage backend not initialized; BatchingQueue's store.ready is false, so length returns null.
fix
Await store.setup() if used directly, or ensure queue is constructed after store is ready. Use optional chaining: queue.length ?? 0.
TypeError: store.dequeue is not a function
Custom store missing dequeue method or using wrong reference; MemoryStore and RedisStore include it.
fix
Implement dequeue(batchSize) that returns a Promise of array of items, or use one of the built-in stores.
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
47 hits · last 30 days
node
40
OpenAI (training)
1
Resources
batching-queue — npm install batching-queue · libregistry