Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Worker
✓ import { Worker } from 'node-resque';
✗ const Worker = require('node-resque').Worker;
ESM import is preferred since v6 due to TypeScript source. CommonJS `require` still works for transpiled output but type definitions are for ESM.
Scheduler
✓ import { Scheduler } from 'node-resque';
✗ const Scheduler = require('node-resque').Scheduler;
The Scheduler manages delayed jobs and performs cluster cleanup.
Queue
✓ import { Queue } from 'node-resque';
✗ const Queue = require('node-resque').Queue;
The Queue is the primary interface for enqueuing and managing jobs.
Job
✓ import type { Job } from 'node-resque';
Recommended for TypeScript users to define job interfaces.
This quickstart demonstrates how to set up a node-resque worker, scheduler, and queue, connect them to Redis, define and enqueue jobs (including delayed jobs), and handle job outcomes.
import { Worker, Scheduler, Queue } from "node-resque";
const connectionDetails = {
pkg: "ioredis",
host: "127.0.0.1",
password: null,
port: 6379,
database: 0,
};
const jobs = {
'testJob': {
perform: async (a: number, b: number) => {
const result = a + b;
console.log(`Job 'testJob' performed with ${a} + ${b} = ${result}`);
return result;
},
},
'delayedJob': {
perform: async (message: string) => {
console.log(`Delayed job received: ${message}`);
return `Processed: ${message}`;
}
}
};
async function boot() {
const queue = new Queue({ connection: connectionDetails, jobs });
await queue.connect();
const worker = new Worker({ connection: connectionDetails, queues: ['default'], jobs });
worker.on('start', () => console.log('Worker started'));
worker.on('end', () => console.log('Worker ended'));
worker.on('success', (queue, job, result) => console.log(`Job success in ${queue}: ${JSON.stringify(job)} => ${result}`));
worker.on('failure', (queue, job, error) => console.error(`Job failure in ${queue}: ${JSON.stringify(job)} => ${error}`));
worker.on('error', (error, queue, job) => console.error(`Worker error: ${error} in ${queue} for ${JSON.stringify(job)}`));
const scheduler = new Scheduler({ connection: connectionDetails, jobs });
scheduler.on('start', () => console.log('Scheduler started'));
scheduler.on('end', () => console.log('Scheduler ended'));
scheduler.on('error', (error, queue, job) => console.error(`Scheduler error: ${error} in ${queue} for ${JSON.stringify(job)}`));
await worker.connect();
await worker.start();
await scheduler.connect();
await scheduler.start();
// Enqueue a simple job
await queue.enqueue('default', 'testJob', [1, 2]);
// Enqueue a delayed job to run in 5 seconds
await queue.enqueueIn(5 * 1000, 'default', 'delayedJob', ['This is a delayed message!']);
console.log('Jobs enqueued. Waiting for workers...');
// Keep the process alive for a bit to allow jobs to process
setTimeout(async () => {
await worker.end();
await scheduler.end();
await queue.end();
console.log('Node-resque example finished.');
process.exit();
}, 10000);
}
boot().catch(console.error);
Errors
Common errors & fixes
TypeError: require is not a function
Attempting to use CommonJS `require()` syntax in an ESM-context (e.g., `"type": "module"` in `package.json`) for a module that primarily supports ESM or provides ESM type definitions, particularly after v6's TypeScript transition.
fixUse ESM `import` statements: `import { Worker } from 'node-resque';`. If you must use `require()`, consider setting `"type": "commonjs"` in your `package.json` or explicitly compiling to CommonJS if using TypeScript. Error: connect ECONNREFUSED 127.0.0.1:6379
The Redis server is not running or is not accessible at the specified host and port.
fixEnsure your Redis server is running and configured to accept connections on the host and port specified in your `connectionDetails`. Check firewall rules or Redis configuration (`redis.conf`).
UnhandledPromiseRejectionWarning: Unhandled promise rejection
An `async` job's `perform` function or other asynchronous operation within node-resque threw an error or rejected a promise without being caught by a `try/catch` block or `.catch()` handler.
fixAlways wrap `async` operations in `try/catch` blocks within your job `perform` functions and add `.catch()` handlers to any promises. Implement `worker.on('error', ...)` and `queue.on('error', ...)` listeners to handle errors gracefully. TypeError: job.perform is not a function
The `jobs` object passed to the Worker or Queue constructor does not correctly define a function for the job name being enqueued or processed.
fixEnsure the `jobs` object contains a key matching the job name, and its value is an object with a `perform` property that is an `async` function, e.g., `{ 'myJobName': { perform: async (arg) => { /* ... */ } } }`. Audit
Dependencies
ioredisrequiredOfficial Redis client recommended and used for connections.