🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@socket.io/postgres-adapter

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@socket.io/postgres-adapter

The Socket.IO Postgres adapter, allowing to broadcast events between several Socket.IO servers

0.4.0
latest
Source
npm
Version published
Weekly downloads
47K
-28.26%
Maintainers
0
Weekly downloads
 
Created
Source

Socket.IO Postgres adapter

The @socket.io/postgres-adapter package allows broadcasting packets between multiple Socket.IO servers.

Diagram of Socket.IO packets forwarded through PostgreSQL

Table of contents

  • Supported features
  • Installation
  • Usage
  • License

Supported features

Featuresocket.io versionSupport
Socket management4.0.0:white_check_mark: YES (since version 0.1.0)
Inter-server communication4.1.0:white_check_mark: YES (since version 0.1.0)
Broadcast with acknowledgements4.5.0:white_check_mark: YES (since version 0.3.0)
Connection state recovery4.6.0:x: NO

Installation

npm install @socket.io/postgres-adapter

Usage

import { Server } from "socket.io";
import { createAdapter } from "@socket.io/postgres-adapter";
import pg from "pg";

const io = new Server();

const pool = new pg.Pool({
  user: "postgres",
  host: "localhost",
  database: "postgres",
  password: "changeit",
  port: 5432,
});

pool.query(`
  CREATE TABLE IF NOT EXISTS socket_io_attachments (
      id          bigserial UNIQUE,
      created_at  timestamptz DEFAULT NOW(),
      payload     bytea
  );
`);

pool.on("error", (err) => {
  console.error("Postgres error", err);
});

io.adapter(createAdapter(pool));
io.listen(3000);

License

MIT

Keywords

socket.io

FAQs

Package last updated on 17 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts