{"id":19066517,"url":"https://github.com/geut/fastify-uws","last_synced_at":"2025-04-14T21:02:46.688Z","repository":{"id":88986005,"uuid":"548414441","full_name":"geut/fastify-uws","owner":"geut","description":"uWebSocket.js for fastify","archived":false,"fork":false,"pushed_at":"2024-10-17T02:44:44.000Z","size":512,"stargazers_count":54,"open_issues_count":2,"forks_count":5,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-14T21:02:25.247Z","etag":null,"topics":["fastify","fastify-plugin","nodejs","uwebsocketjs","uwebsockets","uws","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/geut.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-09T14:20:05.000Z","updated_at":"2025-03-12T23:47:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"6bb403b1-9964-4eaa-8685-3ce6bfdaa87f","html_url":"https://github.com/geut/fastify-uws","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"27edb529aa7c3f17df16ce9f5ce47a9b27db1faf"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geut%2Ffastify-uws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geut%2Ffastify-uws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geut%2Ffastify-uws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/geut%2Ffastify-uws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/geut","download_url":"https://codeload.github.com/geut/fastify-uws/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248961196,"owners_count":21189991,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify","fastify-plugin","nodejs","uwebsocketjs","uwebsockets","uws","websocket"],"created_at":"2024-11-09T00:57:09.675Z","updated_at":"2025-04-14T21:02:46.665Z","avatar_url":"https://github.com/geut.png","language":"JavaScript","readme":"![uWebSockets.js for fastify](.github/assets/logo.png 'uWebSockets.js for fastify')\n\n# fastify-uws\n[uWebSockets.js](https://github.com/uNetworking/uWebSockets.js) for fastify\n\n![Tests](https://github.com/geut/fastify-uws/actions/workflows/test.yml/badge.svg)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard--ext-05ae89.svg)](https://github.com/tinchoz49/eslint-config-standard-ext)\n[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat)](https://github.com/RichardLitt/standard-readme)\n\n[![Made by GEUT][geut-badge]][geut-url]\n\n## Install\n\n```\n$ npm install @geut/fastify-uws\n```\n\n## Usage\n\n```javascript\nimport { getUws, serverFactory, WebSocketStream } from '@geut/fastify-uws'\nimport fastifyUwsPlugin from '@geut/fastify-uws/plugin'\nimport fastify from 'fastify'\n\nconst app = fastify({\n  serverFactory\n})\n\nawait app.register(fastifyUwsPlugin)\n\napp.addHook('onReady', async () =\u003e {\n  // access to uws app\n  const uwsApp = getUws(app)\n})\n\napp.websocketServer.on('open', (ws) =\u003e {\n  console.log('OPEN')\n})\n\napp.websocketServer.on('close', (ws) =\u003e {\n  console.log('CLOSE')\n})\n\napp\n  .route({\n    method: 'GET',\n    url: '/',\n    handler(req, reply) {\n      return 'hello from http endpoint'\n    },\n    uws: {\n      // cache subscription topics to produce less memory allocations\n      topics: [\n        'home/sensors/ligth',\n        'home/sensors/temp'\n      ]\n    },\n    uwsHandler(conn) {\n      conn.subscribe('home/sensors/temp')\n      conn.on('message', (message) =\u003e {\n        conn.publish('home/sensors/temp', 'random message')\n      })\n      conn.send(JSON.stringify({ hello: 'world' }))\n    }\n  })\n  .get('/stream', { uws: true }, (conn) =\u003e {\n    const stream = new WebSocketStream(conn)\n    stream.on('data', (data) =\u003e {\n      console.log('stream data from /stream')\n    })\n  })\n  .listen({\n    port: 3000\n  }, (err) =\u003e {\n    err \u0026\u0026 console.error(err)\n  })\n```\n\n# Benchmarks\n\n* __Machine:__ linux x64 | 2 vCPUs | 6.8GB Mem\n* __Node:__ `v18.15.0`\n* __Run:__ Wed Apr 12 2023 19:06:58 GMT+0000 (Coordinated Universal Time)\n* __Method:__ `autocannon -c 100 -d 40 -p 10 localhost:3000` (two rounds; one to warm-up, one to measure)\n\n|                          | Version | Router | Requests/s | Latency (ms) | Throughput/Mb |\n| :--                      | --:     | --:    | :-:        | --:          | --:           |\n| fastify-uws              | 1.0.0   | ✓      | 84001.6    | 11.50        | 12.58         |\n| 0http                    | v3.5.1  | ✓      | 50275.2    | 19.41        | 8.97          |\n| bare                     | 10.13.0 | ✗      | 49063.2    | 19.94        | 8.75          |\n| h3                       | 1.6.4   | ✗      | 48583.2    | 20.10        | 7.97          |\n| fastify                  | 4.15.0  | ✓      | 48141.6    | 20.30        | 8.63          |\n| h3-router                | 1.6.4   | ✓      | 48025.6    | 20.34        | 7.88          |\n| polka                    | 0.5.2   | ✓      | 47676.0    | 20.49        | 8.50          |\n| server-base              | 7.1.32  | ✗      | 47286.4    | 20.68        | 8.43          |\n| server-base-router       | 7.1.32  | ✓      | 46884.0    | 20.85        | 8.36          |\n| yeps                     | 1.1.1   | ✗      | 45748.0    | 21.36        | 8.16          |\n| connect                  | 3.7.0   | ✗      | 45615.2    | 21.44        | 8.14          |\n| connect-router           | 1.3.8   | ✓      | 44720.0    | 21.91        | 7.97          |\n| vapr                     | 0.6.0   | ✓      | 43516.0    | 22.48        | 7.14          |\n| spirit                   | 0.6.1   | ✗      | 43287.2    | 22.64        | 7.72          |\n| spirit-router            | 0.5.0   | ✓      | 41488.0    | 23.64        | 7.40          |\n| polkadot                 | 1.0.0   | ✗      | 39672.8    | 24.73        | 7.07          |\n| koa                      | 2.14.2  | ✗      | 38013.4    | 25.80        | 6.78          |\n| yeps-router              | 1.2.0   | ✓      | 36993.8    | 26.54        | 6.60          |\n| take-five                | 2.0.0   | ✓      | 36582.2    | 26.86        | 13.15         |\n| koa-isomorphic-router    | 1.0.1   | ✓      | 36292.6    | 27.07        | 6.47          |\n| restify                  | 11.1.0  | ✓      | 35689.0    | 27.53        | 6.43          |\n| koa-router               | 12.0.0  | ✓      | 33882.2    | 29.03        | 6.04          |\n| restana                  | 4.9.7   | ✓      | 33645.4    | 29.26        | 6.00          |\n| hapi                     | 21.3.1  | ✓      | 32087.2    | 30.68        | 5.72          |\n| express                  | 4.18.2  | ✓      | 11337.0    | 87.64        | 2.02          |\n| fastify-big-json         | 4.15.0  | ✓      | 11012.2    | 90.32        | 126.70        |\n| express-with-middlewares | 4.18.2  | ✓      | 10000.8    | 99.45        | 3.72          |\n| trpc-router              | 10.19.1 | ✓      | 6594.1     | 150.95       | 1.97          |\n| foxify                   | 0.10.20 | ✓      | N/A        | N/A          | N/A           |\n| galatajs                 | 0.1.1   | ✓      | N/A        | N/A          | N/A           |\n| micro-route              | 2.5.0   | ✓      | N/A        | N/A          | N/A           |\n| micro                    | 10.0.1  | ✗      | N/A        | N/A          | N/A           |\n| microrouter              | 3.1.3   | ✓      | N/A        | N/A          | N/A           |\n| total.js                 | 3.4.13  | ✓      | N/A        | N/A          | N/A           |\n\n## Issues\n\n:bug: If you found an issue we encourage you to report it on [github](https://github.com/geut/fastify-uws/issues). Please specify your OS and the actions to reproduce it.\n\n## Contributing\n\n:busts_in_silhouette: Ideas and contributions to the project are welcome. You must follow this [guideline](https://github.com/geut/fastify-uws/blob/main/CONTRIBUTING.md).\n\n## License\n\nMIT © A [**GEUT**](http://geutstudio.com/) project\n\n[geut-url]: https://geutstudio.com\n[geut-badge]: https://img.shields.io/badge/Made%20By-GEUT-4f5186?style=for-the-badge\u0026link=https://geutstudio.com\u0026labelColor=white\u0026logo=data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCABAAEADASIAAhEBAxEB/8QAGwAAAgIDAQAAAAAAAAAAAAAABAYDBQACBwH/xAA0EAACAQMBBAcGBgMAAAAAAAABAgMABBEFBhIhQRMiMVFhgcEUIzJxkbFCUmKh0fAkcuH/xAAYAQADAQEAAAAAAAAAAAAAAAABAwQCAP/EACARAAMAAwACAgMAAAAAAAAAAAABAgMRIRIxBEEiM1H/2gAMAwEAAhEDEQA/AOgVlau6xoXdgqqMkk8AKV9U2oYs0WngBRw6VhxPyFamXXoDeiz1PUbmzuujQIUKgjIqGLXnz72FSO9TikfVbi6uXWSSaWRuzixNBx3VzCepNIvgTw+hpjwv+iGr3tM6xa30F2PdP1uangRRNc70fUbi4JLIVaPskXgM/wA076Ze+2W+WwJF4MPWlNaemajI2/GvYbWVlZQHCptZqLNKLGJsKoDSY5nkKorKzlvrlYIRlm5nsA7zWX8pnv55SfikJ/emPZGDcs7m6CguTuL5DPrVf64Me2F2mzNhAg6ZTO/MsSB9BW15s1pt1GVEPRHvQ+hqbTNT9sZ0kCpIOIA5ij5ZEijaSRgqqMkmpVkb7sMuWtoV73S49L3I4B7kjq57c881BZ6vFpuoKjq7dIvYBw8PtUOqX1xcSxoJXw8mQuewVW3vX1eFR+Fcn96OLVvpFzz8kM020kp4QwIvixzVpot5Je2bSTEFw5HAY7qUKadnIymm7x/G5I+3pTskzM8G4rqq6JGpI8E1wi8HR2H0NT7P6rcRKUEzYR9/czgEf0VabV2JgvhdKPdzdvg399aVG37K4Esfw/3hTU1S2NpNrSHqax9q/wAzTm3lY5KA4ZTQl2mo9CWljncL+cnA+tVVhqeSGt5mik5qDg/9o+XVb6aFonuDusMHqjP2qavjbfGTPX3xgTstrm4uGDSEYVV+woWPMKy3dzwd+JHcOQrdkgtyZpXJb87nJ8qqr68a7cKgIjB4DmadGNQjohs9i1C66Xqtvbx+EjIp10jaOMLBaPasDwRTGc5PyNJ1rb9EN5/jP7U17KaaZJvbpV6icI88z3+VG0vH8ipJJ8Ga8tIr22eCYZVh5g94pC1TTJtPmMU67yH4XxwYV0So54IriIxzRrIh7QwzSIyOTbWzlElkCcxtjwNedHeKMCVseDmnq72UgkJa1maL9LDeH81XvspfA9WSBh/sR6U9XD+zDQp+yTSNmR/MnJomG3SLiBlu80zQ7JXTH31xEg/Tlj6Vb2OzljaEO6meQc5OweVc8koOmUGjaFLfuss4MdsOOewv8v5p0ijSGNY41CoowAOQrbsr2p7t0zSWj//Z\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeut%2Ffastify-uws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeut%2Ffastify-uws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeut%2Ffastify-uws/lists"}