GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - tinyhttp/tinyws: 🚡 tiny WebSocket middleware for Node.js

BranchesTags
Open more actions menu

Latest commit

 

History

65 Commits
65 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.husky
.husky
 
 
.vscode
.vscode
 
 
examples
examples
 
 
src
src
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.huskyrc.json
.huskyrc.json
 
 
CLAUDE.md
CLAUDE.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
biome.json
biome.json
 
 
bun.lockb
bun.lockb
 
 
commitlint.config.js
commitlint.config.js
 
 
logo.svg
logo.svg
 
 
package.json
package.json
 
 
tsconfig.build.json
tsconfig.build.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

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<Request & TinyWSRequest>()

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!')
  }
})

const server = app.listen(3000)
tinyws(app, server)

Restricting WebSocket to specific paths

You can restrict WebSocket handling to specific paths using the paths option:

// Single path
tinyws(app, server, { paths: '/ws' })

// Multiple paths
tinyws(app, server, { paths: ['/ws', '/socket'] })

See examples for express and polka integration.

About

🚡 tiny WebSocket middleware for Node.js

npm.im/tinyws

Topics

expresshttpjavascriptnodejspolkaservertinyhttpwebsocketws

Resources

Readme
MIT license
Activity
Custom properties

Stars

419 stars

Watchers

3 watching

Forks

16 forks
Report repository

Releases

Sponsor this project

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.