Home

Awesome

<div align="center"> <img src="https://raw.githubusercontent.com/tinyhttp/tinyws/master/logo.svg" alt="tinyws"> <p><sub>🚡 tiny WebSocket middleware for Node.js</sub></p> <br />

Version Downloads GitHub Workflow Status Codecov

</div>

tinyws is a WebSocket middleware for Node.js based on ws, inspired by koa-easy-ws.

Check the chat example out to get familiar with tinyws.

Features

Why not express-ws?

because express-ws is...

Install

pnpm i ws tinyws

Example

import { App, Request } from '@tinyhttp/app'
import { tinyws, TinyWSRequest } from 'tinyws'

const app = new App<any, Request & TinyWSRequest>()

app.use(tinyws())

app.use('/ws', async (req, res) => {
  if (req.ws) {
    const ws = await req.ws()

    return ws.send('hello there')
  } else {
    res.send('Hello from HTTP!')
  }
})

app.listen(3000)

See examples for express and polka integration.