Skip to content


Repository files navigation


Postgres Message Queue (PGMQ) JavaScript Client Library

version weekly downloads license


As always:

npm i pgmq-js


First, Start a Postgres instance with the PGMQ extension installed:

docker run -d --name postgres -e POSTGRES_PASSWORD=password -p 5432:5432


import { Pgmq } from 'pgmq-js';

console.log('Connecting to Postgres...');
const pgmq = await{
  host: 'localhost',
  database: 'postgres',
  password: 'password',
  port: 5432,
  user: 'postgres',
  ssl: false,
}).catch((err) => {
  console.error('Failed to connect to Postgres', err);

const qName = 'my_queue';
console.log(`Creating queue ${qName}...`);
await pgmq.queue.create(qName).catch((err) => {
  console.error('Failed to create queue', err);

interface Msg {
  id: number;
  name: string;
const msg: Msg = { id: 1, name: 'testMsg' };
console.log('Sending message...');
const msgId = await pgmq.msg.send(qName, msg).catch((err) => {
  console.error('Failed to send message', err);

const vt = 30;
const receivedMsg = await<Msg>(qName, vt).catch((err) => {
  console.error('No messages in the queue', err);

console.log('Received message...');
console.dir(receivedMsg.message, { depth: null });

console.log('Archiving message...');
await pgmq.msg.archive(qName, msgId).catch((err) => {
  console.error('Failed to archive message', err);


Supported Functionalities