{"id":13836180,"url":"https://github.com/gj/fastify-ws","last_synced_at":"2025-03-17T07:32:09.383Z","repository":{"id":26143937,"uuid":"107455928","full_name":"gj/fastify-ws","owner":"gj","description":null,"archived":false,"fork":false,"pushed_at":"2022-12-08T15:46:15.000Z","size":626,"stargazers_count":55,"open_issues_count":19,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-26T12:43:30.703Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/gj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-18T19:53:20.000Z","updated_at":"2023-02-28T03:04:17.000Z","dependencies_parsed_at":"2023-01-14T04:06:47.149Z","dependency_job_id":null,"html_url":"https://github.com/gj/fastify-ws","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gj%2Ffastify-ws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gj%2Ffastify-ws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gj%2Ffastify-ws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gj%2Ffastify-ws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gj","download_url":"https://codeload.github.com/gj/fastify-ws/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243818121,"owners_count":20352629,"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":[],"created_at":"2024-08-04T15:00:37.591Z","updated_at":"2025-03-17T07:32:09.069Z","avatar_url":"https://github.com/gj.png","language":"JavaScript","readme":"# fastify-ws\n\n[![Build Status](https://travis-ci.org/gj/fastify-ws.svg?branch=master)](https://travis-ci.org/gj/fastify-ws) [![npm version](https://badge.fury.io/js/fastify-ws.svg)](https://www.npmjs.com/package/fastify-ws)\n\nWebSocket support for [Fastify](https://github.com/fastify/fastify) built on the [ws](http://npm.im/ws) and [uws](http://npm.im/uws) libraries.\n\n## Example\n\nIn `server.js`:\n\n```js\n'use strict'\n\nconst fastify = require('fastify')()\n\nfastify.register(require('fastify-ws'))\n\nfastify.ready(err =\u003e {\n  if (err) throw err\n\n  console.log('Server started.')\n\n  fastify.ws\n    .on('connection', socket =\u003e {\n      console.log('Client connected.')\n\n      socket.on('message', msg =\u003e socket.send(msg)) // Creates an echo server\n\n      socket.on('close', () =\u003e console.log('Client disconnected.'))\n    })\n})\n\nfastify.listen(34567)\n```\n\nThen run `node server.js` and navigate to `http://localhost:34567` in your browser. In the browser's JavaScript console, open a client-side WebSocket connection:\n\n```js\nconst host = location.origin.replace(/^http/, 'ws')\nconst ws = new WebSocket(host)\nws.onmessage = msg =\u003e console.log(msg.data)\n```\n\nThen, still in the browser console, send some messages to the server and watch as they're echoed back to you:\n\n```js\nws.send('WebSockets are awesome!')\n// =\u003e undefined\n// LOG: WebSockets are awesome!\n```\n\n## Notes\n\nThe creator of `uws` has ceased development on `uws` and started working on their new project, [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js). If you want high-performance web socket support in Fastify, the last real release of `uws` (10.148.1) is probably your best bet, but given that it is now an abandoned project I can't recommend anyone use it for any non-throwaway projects. If you're using this library, I'd recommend you stick with the default `ws` option.\n\nIn addition, if you choose to use `uws` as your WebSocket library, ensure that you have configured your system properly and understand that the API is a slightly reduced subset of `ws`'s.\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","funding_links":[],"categories":["\u003ch2 align=\"center\"\u003eAwesome Fastify\u003c/h2\u003e"],"sub_categories":["\u003ch2 align=\"center\"\u003eEcosystem\u003c/h2\u003e"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgj%2Ffastify-ws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgj%2Ffastify-ws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgj%2Ffastify-ws/lists"}