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.fixUse .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.fixUse 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).fixCall 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+).
fixUse 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.
fixAwait 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.
fixImplement dequeue(batchSize) that returns a Promise of array of items, or use one of the built-in stores.
Audit
Dependencies
No dependency data recorded yet.