{"id":47572,"library":"fastify-ws","title":"fastify-ws","description":"Basic WebSocket support for Fastify built on the ws and uws libraries. Current stable version is 1.0.3, with infrequent releases. It provides a simple plugin to add WebSocket functionality to Fastify, exposing a `fastify.ws` WebSocket.Server instance. Supports both `ws` (default) and `uws` backends, but `uws` is abandoned. Differentiator: minimal plugin for legacy Fastify versions, but not actively maintained and lacks full lifecycle management compared to @fastify/websocket.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/gj/fastify-ws","tags":["javascript","fastify","websocket","ws","uws"],"install":[{"cmd":"npm install fastify-ws","lang":"bash","label":"npm"},{"cmd":"yarn add fastify-ws","lang":"bash","label":"yarn"},{"cmd":"pnpm add fastify-ws","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; must be installed alongside fastify-ws.","package":"fastify","optional":false},{"reason":"Default WebSocket implementation; used unless uws is configured.","package":"ws","optional":true},{"reason":"Optional alternative WebSocket backend; abandoned.","package":"uws","optional":true}],"imports":[{"note":"ESM default import; CommonJS require is also valid but not recommended for TypeScript.","wrong":"const fastifyWs = require('fastify-ws')","symbol":"default","correct":"import fastifyWs from 'fastify-ws'"},{"note":"After registration, the WebSocket.Server instance is attached to `fastify.ws`. Do not use `fastify.websocket`.","wrong":"const wss = fastify.websocket","symbol":"fastify.ws","correct":"fastify.register(fastifyWs)\nconst wss = fastify.ws"},{"note":"Event name is 'connection', not 'connect'. 'socket' is the WebSocket instance.","wrong":"fastify.ws.on('connect', (socket) => { ... })","symbol":"connection","correct":"fastify.ws.on('connection', (socket) => { ... })"}],"quickstart":{"code":"const fastify = require('fastify')()\n\nfastify.register(require('fastify-ws'))\n\nfastify.ready(err => {\n  if (err) throw err\n\n  fastify.ws.on('connection', socket => {\n    socket.on('message', msg => socket.send(msg))\n  })\n})\n\nfastify.listen({ port: 3000 }, (err, address) => {\n  if (err) throw err\n  console.log(`Server listening on ${address}`)\n})","lang":"javascript","description":"Registers fastify-ws plugin, waits for ready, then adds an echo WebSocket server."},"warnings":[{"fix":"Use @fastify/websocket which is the official Fastify WebSocket plugin.","message":"This package is not actively maintained. Consider using @fastify/websocket instead.","severity":"deprecated","affected_versions":"*"},{"fix":"Do not configure uws; stick with default ws backend.","message":"The uws backend is abandoned and may have security vulnerabilities. Default is ws.","severity":"gotcha","affected_versions":"*"},{"fix":"Call fastify.ready() or await fastify.ready() before using fastify.ws.","message":"Must call fastify.ready() before accessing fastify.ws or the server will not start.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.3':20 'abandon':50 'activ':60 'add':30 'backend':46 'basic':4 'built':9 'compar':67 'current':16 'default':43 'differenti':51 'expos':35 'fastifi':2,8,34,56,71 'fastify-w':1 'fastify.ws':37 'fastify/websocket':69 'full':64 'function':32 'infrequ':22 'instanc':39 'javascript':70 'lack':63 'legaci':55 'librari':15 'lifecycl':65 'maintain':61 'manag':66 'minim':52 'plugin':28,53 'provid':25 'releas':23 'simpl':27 'stabl':17 'support':6,40 'uw':14,45,48,74 'version':18,57 'websocket':5,31,72 'websocket.server':38 'ws':3,12,42,73","created_at":"2026-06-07T16:52:11.688758+00:00","updated_at":"2026-06-07T16:52:11.688758+00:00","problems":[{"fix":"Ensure fastify.register(require('fastify-ws')) is called and then await fastify.ready() before accessing fastify.ws.","cause":"Accessing fastify.ws before registering the plugin or before fastify.ready() is called.","error":"TypeError: Cannot read property 'on' of undefined"},{"fix":"Use import fastifyWs from 'fastify-ws' inside a \"type\": \"module\" package or use require().","cause":"Using import syntax without proper ESM configuration or missing .mjs extension.","error":"ERR_MODULE_NOT_FOUND: Cannot find module 'fastify-ws'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/gj/fastify-ws#readme","github":"https://github.com/gj/fastify-ws","docs":null,"changelog":null,"pypi":null,"npm":"fastify-ws","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}