Registry / messaging / socket.io-adapter-postgres

socket.io-adapter-postgres

JSON →
library1.2.1jsnpmunverified

PostgreSQL-based adapter for Socket.IO enabling horizontal scaling by broadcasting and emitting events across multiple Socket.IO instances. Version 1.2.1 is the latest stable release, with infrequent updates (no recent commits). Unlike Redis-based adapters, it uses PostgreSQL's LISTEN/NOTIFY for pub/sub, making it suitable for teams already running PostgreSQL. Supports remote join, leave, and disconnect across nodes.

npm install socket.io-adapter-postgres
INSTALL
IMPORT
SIG · SOCKET.IO-ADAPTER-
S
socket.io-adapter-postgres
messagingjavascriptv1.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.

default
import adapter from 'socket.io-adapter-postgres'
const adapter = require('socket.io-adapter-postgres').default
Default export is the adapter factory function. ESM usage requires named import as shown.
PostgresAdapter
import { PostgresAdapter } from 'socket.io-adapter-postgres'
const { PostgresAdapter } = require('socket.io-adapter-postgres')
Named export for the class itself; CommonJS require works but named import is preferred for TypeScript.
require
const adapter = require('socket.io-adapter-postgres')
CommonJS style: adapter is a function. This is the legacy pattern.

Connects Socket.IO to PostgreSQL for multi-process broadcasting using the postgres adapter.

const io = require('socket.io')(3000); const postgresAdapter = require('socket.io-adapter-postgres'); const adapter = postgresAdapter({ host: 'localhost', port: 5432 }); io.adapter(adapter); io.on('connection', (socket) => { console.log('Client connected'); socket.emit('message', 'Hello from server'); });
Debug
Known issues
gotchaThe adapter requires PostgreSQL's LISTEN/NOTIFY feature; ensure your PostgreSQL user has permission to use LISTEN and NOTIFY.
fix
Grant the user the ability to execute LISTEN/NOTIFY, or use a superuser for development.
affects: >=1.0.0
gotchaIf you supply custom pubClient and subClient, they must be from the 'pg' library with compatible APIs; using different PostgreSQL clients may break.
fix
Use the 'pg' package and ensure pubClient is a Pool, subClient is a Client.
affects: >=1.0.0
gotchaThis package is derived from socket.io-redis but not actively maintained; latest release is 1.2.1 from 2019. No support for Socket.IO v4 or newer.
fix
Consider using socket.io-redis or a maintained adapter for Socket.IO v4+ compatibility.
affects: >=1.0.0
gotchaThe adapter uses a single LISTEN/NOTIFY channel; if many instances publish heavily, performance may degrade due to PostgreSQL limitations.
fix
Limit the number of Socket.IO instances or use Redis for high-throughput scenarios.
affects: >=1.0.0
Errors
Common errors & fixes
Error: listen EADDRINUSE :::5432
PostgreSQL port already in use by another process or adapter configuration.
fix
Ensure PostgreSQL is running on the specified port, or change the port in the adapter options.
TypeError: io.adapter is not a function
Using an older version of Socket.IO (<1.0) where adapter method is not available.
fix
Upgrade Socket.IO to version 1.0 or later.
Unhandled rejection Error: sorry, too many clients already
PostgreSQL connection pool exhausted; too many Socket.IO instances or high concurrency.
fix
Increase max connections in PostgreSQL configuration or limit pool size in adapter options (not directly supported).
Upgrade
Version history
1.2.1latest on npm
Audit
Dependencies
pgrequiredPostgreSQL client required for pool and client instances
socket.io-adapterrequiredBase adapter class from Socket.IO
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
socket.io-adapter-postgres — npm install socket.io-adapter-postgres · libregistry