Socket
Socket
Sign inDemoInstall

tinyws

Package Overview
Dependencies
4
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tinyws

Tiny WebSocket middleware for Node.js based on ws.


Version published
Weekly downloads
6.5K
increased by1.14%
Maintainers
1
Install size
6.44 kB
Created
Weekly downloads
 

Readme

Source
tinyws

🚡 tiny WebSocket middleware for Node.js


Version Downloads GitHub Workflow Status Codecov

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

  • Small size (498B)
  • Easy to use (only req.ws and nothing else)
  • Framework-agnostic (works with tinyhttp, express etc)
  • Written in TypeScript
  • Pure ESM

Why not express-ws?

because express-ws is...

  • Abandoned since 2018 💀
  • Doesn't come with types out of the box (have to install @types/express-ws)
  • Not compatible with tinyhttp and polka
  • Buggy as hell
  • Doesn't have tests

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)

Keywords

FAQs

Last updated on 01 Oct 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc