Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tinyhttp/tinyws
๐ก tiny WebSocket middleware for Node.js
https://github.com/tinyhttp/tinyws
express http javascript nodejs polka server tinyhttp websocket ws
Last synced: 4 days ago
JSON representation
๐ก tiny WebSocket middleware for Node.js
- Host: GitHub
- URL: https://github.com/tinyhttp/tinyws
- Owner: tinyhttp
- License: mit
- Created: 2021-05-10T15:48:25.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2023-09-24T15:43:14.000Z (about 1 year ago)
- Last Synced: 2024-05-23T07:54:51.490Z (5 months ago)
- Topics: express, http, javascript, nodejs, polka, server, tinyhttp, websocket, ws
- Language: TypeScript
- Homepage: https://npm.im/tinyws
- Size: 272 KB
- Stars: 398
- Watchers: 4
- Forks: 15
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-web-cn - tinyws - ็จไบ Node.js ็ๅพฎๅ WebSocket ไธญ้ดไปถ (Uncategorized / Uncategorized)
- awesome-made-by-indonesian - tinyws - `tiny WebSocket middleware for Node.js` *by [tinyhttp](https://github.com/tinyhttp)* (T)
- made-in-indonesia - tinyws - `tiny WebSocket middleware for Node.js` *by [tinyhttp](https://github.com/tinyhttp)* (T)
README
๐ก tiny WebSocket middleware for Node.js
[![Version][v-badge-url]][npm-url] [![Downloads][dl-badge-url]][npm-url] [![GitHub Workflow Status][gh-actions-img]][github-actions] [![Codecov][cov-badge-url]][cov-url]
_**tinyws**_ is a WebSocket middleware for Node.js based on [ws](https://github.com/websockets/ws), inspired by [koa-easy-ws](https://github.com/b3nsn0w/koa-easy-ws).
Check the [chat example](examples/chat) 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](https://github.com/HenningM/express-ws)?
because express-ws is...
- [Abandoned](https://github.com/HenningM/express-ws/issues/135) 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
```sh
pnpm i ws tinyws
```## Example
```ts
import { App, Request } from '@tinyhttp/app'
import { tinyws, TinyWSRequest } from 'tinyws'const app = new App()
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](examples) for express and polka integration.
[v-badge-url]: https://img.shields.io/npm/v/tinyws.svg?style=for-the-badge&color=F55A5A&label=&logo=npm
[npm-url]: https://www.npmjs.com/package/tinyws
[cov-badge-url]: https://img.shields.io/coveralls/github/tinyhttp/tinyws?style=for-the-badge&color=F55A5A
[cov-url]: https://coveralls.io/github/tinyhttp/tinyws
[dl-badge-url]: https://img.shields.io/npm/dt/tinyws?style=for-the-badge&color=F55A5A
[github-actions]: https://github.com/tinyhttp/tinyws/actions
[gh-actions-img]: https://img.shields.io/github/actions/workflow/status/tinyhttp/tinyws/main.yml?branch=master&style=for-the-badge&color=F55A5A&label=&logo=github