Registry / devops / smart-request-queue

smart-request-queue

JSON →
library1.2.1jsnpmunverified

Enterprise-grade request queue for NestJS with Redis support, retries, priorities, and rate limiting. Current stable version is 1.2.1, released under MIT license. This package provides a NestJS module for managing request queues with features like rate limiting per queue, per-key isolation, priority-based execution, retry with exponential backoff, job timeout handling, and cancelation. It supports both in-memory (default) and Redis-backed storage for persistence and distributed events across nodes via Redis Pub/Sub. Key differentiators include typed event streams via RxJS Observable, queue introspection, and support for both function-based and Axios-based jobs. Requires NestJS 9+, reflect-metadata, and rxjs 7+. Ships with TypeScript types and supports dynamic/async module configuration. Suitable for production scenarios where throttling, job queuing, and rate limiting are needed within a NestJS application.

npm install smart-request-queue
INSTALL
IMPORT
SIG · SMART-REQUEST-QUEU
S
smart-request-queue
devopsjavascriptv1.2.1
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.

QueueModule
import { QueueModule } from 'smart-request-queue';
const QueueModule = require('smart-request-queue').QueueModule;
ESM-only since v1.0; CommonJS require still works but import is preferred.
QueueService
import { QueueService } from 'smart-request-queue';
import { QueueService } from 'smart-request-queue/dist/queue.service';
Direct internal path imports are not supported; always import from the package root.
QUEUE_EVENTS
import { QUEUE_EVENTS } from 'smart-request-queue';
import QUEUE_EVENTS from 'smart-request-queue';
QUEUE_EVENTS is a named export, not a default export.

Basic NestJS module setup with in-memory queue and a service that adds a job to the 'api' queue with priority.

import { Module } from '@nestjs/common'; import { QueueModule, QueueService } from 'smart-request-queue'; @Module({ imports: [ QueueModule.forRoot({ requests: [ { name: 'api', requestsCount: 5, requestInterval: '1sec' }, ], }), ], providers: [MyService], }) export class AppModule {} @Injectable() export class MyService { constructor(private readonly queue: QueueService) {} async doSomething() { const result = await this.queue.add({ name: 'api', fn: async () => 'Task completed', priority: 1, }); console.log(result); } }
Debug
Known issues
breakingAs of version 1.0.0, package is ESM-only. CommonJS require may still work in Node >=16 but is not officially supported.
fix
Use ES module imports (import { ... } from 'smart-request-queue') in TypeScript or Node ESM mode.
affects: >=1.0.0
deprecatedIn version 0.x, the module was imported as QueueModule.forRootAsync({...}) with different options. As of 1.0, use forRoot or forRootAsync with the new options shape.
fix
Update imports to the new API; refer to v1 migration guide.
affects: >=1.0.0
gotchaWhen using Redis storage, ensure Redis server is running and the redisOptions are correct. Failure to connect will cause queue operations to throw until the connection is re-established.
fix
Check Redis connectivity and credentials. Use environment variables for configuration.
affects: all
gotchaThe 'axios' and 'fn' options in QueueJob are mutually exclusive. Providing both will cause the fn to be ignored or an error.
fix
Use only one of 'axios' or 'fn' per job.
affects: all
gotchaThe 'key' option for isolation must be provided consistently across related jobs. Missing key means no isolation, which may unintendedly share rate limits.
fix
Always provide a 'key' when per-user/per-tenant isolation is required.
affects: all
Errors
Common errors & fixes
Cannot find module 'smart-request-queue'
Package not installed or missing from node_modules.
fix
Run npm install smart-request-queue and ensure it's in package.json dependencies.
QueueService is not a function
Attempting to use QueueService as a function instead of injecting as a provider.
fix
Inject via constructor: constructor(private queue: QueueService) {}
Error: Queue 'api' not configured
The queue name used in add() does not match any queue defined in QueueModule.forRoot().
fix
Add the queue name to the requests array in the module configuration.
TypeError: Cannot read properties of undefined (reading 'add')
QueueService is undefined because it was not provided in the module.
fix
Make sure QueueModule is imported in your module and that the service using QueueService is in the same module context.
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
@nestjs/commonrequiredPeer dependency required for NestJS module decorators and DI
@nestjs/corerequiredPeer dependency required for NestJS module system
reflect-metadatarequiredPeer dependency required for NestJS reflection
rxjsrequiredPeer dependency required for Observable-based event streams
Agent activity
14 hits · last 30 days
node
12
Resources
smart-request-queue — npm install smart-request-queue · libregistry