tinyws is a lightweight, framework-agnostic WebSocket middleware for Node.js, built upon the popular `ws` library. It enables WebSocket capabilities for HTTP servers, integrating seamlessly with frameworks like tinyhttp, Express, and Polka by exposing a `req.ws()` method. The current stable version is 1.0.0, as of April 2026. This package distinguishes itself from alternatives like `express-ws` by being actively maintained, providing first-class TypeScript support, being pure ESM, and boasting a minimal footprint (under 500B). Its primary release cadence appears to be focused on stability and maintenance rather than rapid feature additions, making it a reliable choice for adding WebSockets to modern Node.js applications.
npm install tinywsVerified import paths — ran on the pinned version, not inferred.
This quickstart initializes a tinyhttp server with tinyws, creating a WebSocket endpoint at `/ws` that echoes messages back to the client. It demonstrates how to access the WebSocket instance via `req.ws()` and handle basic messaging.
Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`). For mixed CJS/ESM projects, use `import()` within an `async` function: `const { tinyws } = await import('tinyws');`Run `npm install ws` or `pnpm i ws` in your project directory.
Follow the pattern `const server = app.listen(PORT); tinyws(app, server);` ensuring both `app` and the raw `http.Server` instance are provided.
Always use `if (req.ws) { const ws = await req.ws(); /* ... */ }` within your route handler to properly establish and interact with the WebSocket.Run `npm install ws` or `pnpm i ws` to add the required WebSocket library.
Ensure `tinyws(app, server, { paths: '/your-ws-path' });` is called after your HTTP server is created, and that the client is connecting to one of the specified `paths`.Ensure your `Request` type is augmented with `TinyWSRequest` (e.g., `App<Request & TinyWSRequest>`) and that you `await req.ws()` to get the WebSocket instance.