uWebSocket.js for fastify

Overview

fastify-uws

uWebSockets.js for fastify

Tests JavaScript Style Guide standard-readme compliant

Made by GEUT

Install

$ npm install @geut/fastify-uws

Usage

import fastify from 'fastify'
import { serverFactory, fastifyUws } from '@geut/fastify-uws'

const app = fastify({
  serverFactory
})

await app.register(fastifyUws)

app.websocketServer.on('open', ws => {
  console.log('OPEN')
})

app.websocketServer.on('close', ws => {
  console.log('CLOSE')
})

app
  .get('/', {
    ws: {
      topics: [
        'home/sensors/ligth',
        'home/sensors/temp'
      ]
    }
  },
  async (req, reply) => {
    if (!reply.ws) {
      return 'hello from http endpoint'
    }

    reply.subscribe('home/sensors/temp')
    reply.on('message', (message) => {
      reply.publish('home/sensors/temp', 'random message')
    })
    reply.send(JSON.stringify({ hello: 'world' }))
  })
  .listen({
    port: 3000
  }, (err) => {
    err && console.error(err)
  })

Benchmarks

Generated from: https://github.com/geut/benchmarks

  • Machine: linux x64 | 2 vCPUs | 6.8GB Mem
  • Node: v14.20.1
  • Run: Thu Oct 13 2022 21:42:53 GMT+0000 (Coordinated Universal Time)
  • Method: autocannon -c 100 -d 40 -p 10 localhost:3000 (two rounds; one to warm-up, one to measure)
Version Router Requests/s Latency Throughput/Mb
fastify-uws 0.0.5 80122.8 12.00 12.00
bare 10.13.0 56154.4 17.32 10.01
polkadot 1.0.0 55499.2 17.52 9.90
polka 0.5.2 55183.2 17.64 9.84
foxify 0.10.20 55168.8 17.63 9.05
micro 9.4.1 55053.6 17.67 9.82
connect 3.7.0 55044.8 17.67 9.82
fastify 4.8.1 54933.6 17.71 9.85
0http 3.4.1 54540.8 17.84 9.73
rayo 1.3.10 53823.2 18.09 9.60
server-base 7.1.32 53657.6 18.14 9.57
server-base-router 7.1.32 52456.8 18.56 9.36
yeps 1.1.1 49796.0 19.58 8.88
restana 4.9.6 48790.4 20.00 8.70
micro-route 2.5.0 47211.2 20.69 8.42
connect-router 1.3.7 46852.8 20.85 8.36
trek-engine 1.0.5 46170.4 21.16 7.57
trek-router 1.2.0 44349.8 22.05 7.27
vapr 0.6.0 43468.8 22.51 7.13
yeps-router 1.2.0 40915.2 23.94 7.30
koa 2.13.4 39010.6 25.14 6.96
total.js 3.4.13 38128.8 25.73 11.67
spirit 0.6.1 37768.0 25.99 6.74
spirit-router 0.5.0 37556.0 26.13 6.70
take-five 2.0.0 36465.0 26.93 13.11
koa-isomorphic-router 1.0.1 35757.4 27.47 6.38
restify 8.6.1 35377.8 27.77 6.38
koa-router 12.0.0 33373.2 29.46 5.95
hapi 20.2.2 29162.8 33.79 5.20
microrouter 3.1.3 28242.0 34.91 5.04
trpc-router 9.27.4 24931.6 39.59 5.52
egg.js 3.3.3 18348.9 53.98 6.56
express 4.18.2 11994.8 82.81 2.14
express-with-middlewares 4.18.2 10532.1 94.37 3.92
express-route-prefix 4.18.2 10291.0 96.63 3.81
fastify-big-json 4.8.1 9940.1 100.11 114.37

Issues

🐛 If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.

Contributing

👥 Ideas and contributions to the project are welcome. You must follow this guideline.

License

MIT © A GEUT project

You might also like...

GraphQL Fastify Server is an implementation of GraphQL.

GraphQL Fastify Server Installation Usage Using cache Middlewares Liveness & Readiness Contributing License Installation npm install --save graphql-fa

Dec 19, 2022

🚀 Blazing Fast S3 Powered CDN ✨ Powered By Fastify, S3 Buckets & Docker!

🚀 WasiCDN Blazing Fast S3 Powered CDN, Powered By Fastify, S3 Compatible Buckets & Docker! Core DockerHub: https://hub.docker.com/r/maximking19/wasic

Aug 31, 2022

NextAuth.js plugin for Fastify.

fastify-next-auth Authentication plugin for Fastify, powered by NextAuth.js. Requirements: fastify-cookie: used to set cookie for tracking sessions. f

Dec 16, 2022

🔥 Blazing Fast API which scrapes Mydramalist.com made using Fastify and Cheerio.

mydramalist API 🔥 Blazing Fast API which scrapes Mydramalist.com made using Fastify and Cheerio. Setup pnpm install node index.js available at http:/

Dec 4, 2022

Real world app using Fastify-DX, Solid.js, Auth0 and GraphQL

Fastify DX and Solid.js In the Real World These are only the essentials to set up a "real world" application with Fastify DX, Solid.js, Auth0 and Grap

Nov 14, 2022

Ergonomic, chaining-based Typescript framework for quick API development for Fastify

Ergonomic, chaining-based Typescript framework for quick API development for Fastify

Ergonomic, chaining-based Typescript framework for quick API development for Fastify Installation pnpm add @t3ned/channel Usage // index.ts import

Aug 2, 2022

End-to-End type safety for REST APIs written in Fastify. Only problem is you have to explicity export and register route handlers. LOL

Chino intelligence in japaneese End-to-End type safety for REST APIs written in Fastify. Only problem is you have to explicity export and register rou

Sep 12, 2022

Api simples de OCR feita com Fastify e Tesseract.js

ocr-api API de OCR simples feita com Fastify e Tesseract.js Iniciando Depois de instalar as depedências, simplesmente inicia com npm run start. Nota:

Oct 8, 2022
Owner
GEUT
Custom JS Software Development Team. Code with opinions.
GEUT
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Supabase client initialization and encapsulation in fastify framework

fastify-supabase Supabase client initialization and encapsulation in fastify framework. Install Install the package with: npm i fastify-supabase --sav

null 19 Aug 2, 2022
API server for AospExtended made with Fastify.

AospExtended API API server for AospExtended made with Fastify. Run Locally Clone the project git clone https://github.com/allstargaurav/aospextende

Gaurav 3 Oct 12, 2022
just a graphql example created by typescript + fastify + mikro-orm(postgresql) + mercurius(graphql adaptor) + type-graphql

fastify-mikro-orm-mercurius-graphql-example A MikroORM boilerplate for GraphQL made with Fastify, Mercurius, Typescript using TypeGraphQL ?? Packages

Vigen 10 Aug 28, 2022
Fastify boilerplate with Vite & Vitest

Fastify boilerplate with Vite & Vitest Enhance your Fastify DX with the power of Vite & Vitest. Features ⚡ All the power of Vite (Next Generation Fron

Emmanuel Salomon 31 Dec 13, 2022
Fastify is a web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture, inspired by Hapi and Express.

Fastify is a web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture, inspired by Hapi and Express.

Jared Hanson 5 Oct 11, 2022
Fastify + Typescript starter

Fastify + Typescript starter A really basic API template powered by: Fastify Typescript EsLint + Prettier Jest + Supertest Available scripts: npm run

Andrea 6 Aug 24, 2022
Simple TypeScript fastify template.

Simple fastify template. Instructions: 1.) Clone the repo 2.) Type npm i to install all dependencies 3.) Type npm run dev to make it autorecompile on

Nick 2 Mar 17, 2022
Run REST APIs in Node.js applications frameworks (Express, Koa, Hapi and Fastify) on top of any Serverless Cloud.

?? Serverless Adapter Install | Usage | Support | Architecture | Credits Run REST APIs and other web applications using your existing Node.js applicat

Vinicius Lourenço 45 Jan 1, 2023