Registry / messaging / nestjs-pgmq

nestjs-pgmq

JSON →
library0.0.5jsnpmunverified

nestjs-pgmq integrates the PGMQ Postgres message queue into NestJS, providing a Bull-compatible API for distributed job processing using existing PostgreSQL infrastructure. Version 0.0.5 – actively developed. Key differentiators: no extra middleware (like Redis), automatic metadata injection (correlationId, producerId), dead letter queues, transactional safety, and graceful shutdown. Alternative to @nestjs/bull for Postgres-native setups.

npm install nestjs-pgmq
INSTALL
IMPORT
SIG · NESTJS-PGMQ
N
nestjs-pgmq
messagingjavascriptv0.0.5
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.

PgmqModule
import { PgmqModule } from 'nestjs-pgmq'
const { PgmqModule } = require('nestjs-pgmq')
ESM module; CommonJS require works but named import is preferred with TypeScript.
Processor
import { Processor } from 'nestjs-pgmq'
import { Processor } from '@nestjs/bull'
Mimics Bull decorators but from nestjs-pgmq package.
InjectQueue
import { InjectQueue } from 'nestjs-pgmq'
import { InjectQueue } from '@nestjs/bull'
Use InjectQueue from nestjs-pgmq; Bull's InjectQueue will not work.

Shows module registration, processor with @Processor/@Process, and queue injection with add method.

// app.module.ts import { Module } from '@nestjs/common'; import { PgmqModule } from 'nestjs-pgmq'; @Module({ imports: [ PgmqModule.forRootAsync({ useFactory: () => ({ connectionString: 'postgres://postgres:postgres@localhost:5432/db', }), }), PgmqModule.registerQueue({ name: 'notifications' }), ], }) export class AppModule {} // notifications.processor.ts import { Processor, Process, PgmqJob } from 'nestjs-pgmq'; @Processor('notifications') export class NotificationsProcessor { @Process('send-email') async handleEmail(job: PgmqJob<{ email: string; body: string }>) { console.log(`Sending email to ${job.data.email}...`); } } // users.service.ts import { Injectable } from '@nestjs/common'; import { InjectQueue, PgmqQueue } from 'nestjs-pgmq'; @Injectable() export class UsersService { constructor(@InjectQueue('notifications') private readonly queue: PgmqQueue) {} async registerUser(email: string) { await this.queue.add('send-email', { email, body: 'Welcome!' }); } }
Debug
Known issues
gotchaTypeScript deep import – If you import from 'nestjs-pgmq/dist/...' it may break module resolution. Always import from 'nestjs-pgmq' package root.
fix
Change import to top-level: import { ... } from 'nestjs-pgmq'
affects: >=0.0.0
gotchaMissing pgmq extension – The library requires the pgmq PostgreSQL extension. Without it, queue operations throw errors.
fix
Run CREATE EXTENSION IF NOT EXISTS pgmq CASCADE; on your Postgres database.
affects: >=0.0.0
gotchaIncorrect peer dependency – NestJS > 10 is required; older versions may have decorator/DI incompatibilities.
fix
Upgrade NestJS to v10+ or check compatibility.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'nestjs-pgmq'
Package not installed or dependency tree broken.
fix
Run npm install nestjs-pgmq pg
ERROR [ExceptionHandler] connectionString is required
Missing or undefined connectionString in PgmqModule.forRootAsync.
fix
Ensure the useFactory returns an object with connectionString property.
ERROR [ExceptionHandler] Queue 'notifications' not registered
PgmqModule.registerQueue not called with the queue name.
fix
Add PgmqModule.registerQueue({ name: 'notifications' }) to your module imports.
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies
pgrequiredPeer dependency for PostgreSQL client. Required to connect to the database.
Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources
nestjs-pgmq — npm install nestjs-pgmq · libregistry