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.
peanar
✓ import peanar from 'peanar'
✗ const peanar = require('peanar')
Default export; ESM-compatible with TypeScript
Job
✓ import { Job } from 'peanar'
✗ const { Job } = require('peanar')
Named export for defining job classes
JobQueue
✓ import { JobQueue } from 'peanar'
Named export for custom queue configuration
Demonstrates setting up a Peanar queue, defining a job class, enqueuing a job, and starting a worker to process jobs.
import peanar, { Job } from 'peanar';
import amqplib from 'amqplib';
const connection = await amqplib.connect('amqp://guest:guest@localhost');
const channel = await connection.createChannel();
const queue = peanar({
name: 'myQueue',
connection,
channel,
});
class MyJob extends Job {
static perform(params: { message: string }) {
console.log(`Processing: ${params.message}`);
}
}
queue.enqueue(MyJob, { message: 'Hello from Peanar!' });
const worker = queue.worker();
worker.start();
Debug
Known issues
gotchaRabbitMQ must be running and accessible; the library will fail silently if connection fails.fixEnsure RabbitMQ server is available and connection URL is correct.
affects: >=0.0.0
breakingIn version 0.18.0, the API changed: 'peanar' now returns a queue instance instead of a factory.fixUpdate code to call peanar(options) directly instead of peanar.createQueue(options).
affects: >=0.18.0 <0.19.0
gotchaJob class must have a static 'perform' method; otherwise jobs will fail silently.fixEnsure every Job subclass defines static perform(params).
affects: >=0.0.0
deprecatedThe 'channel' option is required; omitting it will cause errors in future versions.fixProvide a channel object to peanar options.
affects: >=0.17.0
Errors
Common errors & fixes
TypeError: peanar is not a function
Using require() with default import in an ESM context.
fixUse import peanar from 'peanar' or use require('peanar').default. Error: Job must have a static 'perform' method
Job class does not implement static perform.
fixAdd static perform(params) method to the job class.
Error: Connection closed unexpectedly
RabbitMQ connection lost due to network or server issue.
fixImplement reconnection logic or use a connection manager.
Audit
Dependencies
amqplibrequiredRequired for RabbitMQ connection and channel management
@types/amqpliboptionalTypeScript type definitions for amqplib