🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@prsm/express-keepalive-ws

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prsm/express-keepalive-ws

This is a middleware that creates and exposes a `KeepAliveServer` instance (see [prsm/keepalive-ws](https://github.com/...).

latest
npmnpm
Version
1.2.8
Version published
Maintainers
1
Created
Source

@prsm/express-keepalive-ws

This is a middleware that creates and exposes a KeepAliveServer instance (see prsm/keepalive-ws.

import express from "express";
import createWss, { type WSContext } from "@prsm/express-keepalive-ws";

const app = express();
const server = createServer(app);

const { middleware: ws, wss } = createWss({ /** ... */ });

app.use(ws);

// as a middleware:
app.use("/ws", async (req, res) => {
  if (req.ws) { // <-- req.ws will be defined if the request is a WebSocket request
    const ws = await req.ws(); // handle the upgrade and receive the client WebSocket
    ws.send("Hello WS!"); // send a message to the client
  } else {
    res.send("Hello HTTP!");
  }
});

// as a command server:
wss.registerCommand("echo", (c: WSContext) => {
  const { payload } = c;
  return `echo: ${payload}`;
});

Client-side usage (more at https://github.com/node-prism/keepalive-ws):

import { KeepAliveClient } from "@prsm/keepalive-ws/client";

const opts = { shouldReconnect: true };
const ws = new KeepAliveClient("ws://localhost:PORT", opts);

const echo = await ws.command("echo", "hello!");
console.log(echo); // "echo: hello!"

FAQs

Package last updated on 15 Apr 2025

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