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
- Ultimate-WS [https://github.com/dimdenGD/ultimate-ws]
- Ultimate-express [https://github.com/dimdenGD/ultimate-express]
*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)
npm i ultimate-express-ws
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 **