GithubHelp home page GithubHelp logo

aral / tinyws Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tinyhttp/tinyws

0.0 0.0 0.0 406 KB

๐Ÿšก tiny WebSocket middleware for Node.js

Home Page: https://npm.im/tinyws

License: MIT License

JavaScript 16.61% TypeScript 83.39%

tinyws's Introduction

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)

tinyws's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.