Skip to content

Repository files navigation

Ultimate-Express-WS (alpha)

Drop in replacement for Express-WS library in favour of Ultimate-WS over the traditional WS library.

Makes it easy to add Websocket Endpoints to your Express app while using uWebsockets under the hood through Ultimate-WS.

Checkout

*NOTE If you are already using bun, these libraries will fail (trust me lol)! You have to uninstall bun first and switch to Node JS for these libraries to work.

Main Changes:

  • leverages Ultimate-WS features
  • Type safety
  • Support Subprotocols (like Graphql) [untested]
  • Middleware support + Map Based route storage
  • added custom getRoutes() to view all Websocket endpoints (for debugging)

Installation

npm i ultimate-express-ws

Example With Ultimate-Express

const express = require("ultimate-express"); // or express 
const expressApp = express();
import handleWebsocket from '/services/handleWebsocket.ts'
import {UltimateExpressWS} from 'ultimate-express-ws'

// EXPRESSWS
// export const appInstance = ExpressWS(expressApp);

// Ultimate-Express-WS
export const appInstance = UltimateExpressWS(expressApp, undefined, 
 { 
    wsOptions: {
    perMessageDeflate: true,
    clientTracking: true,
    autoPong: true, 
  }
});
const app = appInstance.app

// Add your websocket endpoint
app.ws('/ws', handleWebsocket)

// appInstance.getRoutes() -- Lists all for your ws routes
// appInstance.getWss() -- the main WebSocket server
// appInstance.app - express app



** This is an early release so use it at your own risk **

About

A drop In replacement for Express-WS when using the Ultimate-WS over WS library

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages