{"id":49713,"library":"websocket-driver","title":"websocket-driver","description":"A complete WebSocket protocol implementation with pluggable I/O, extracted from the Faye project. Current stable version 0.7.5, released August 2020. Supports RFC 6455, draft-75, and draft-76. Handles handshake negotiation, subprotocol selection, extensions via websocket-extensions, message framing (text, binary, ping, pong, close), fragmentation, masking, and close handshake. Decouples protocol details from I/O, allowing use with HTTP servers (http.createServer) or raw TCP (net module). Typically used as a low-level library by higher-level WebSocket libraries like faye-websocket.","status":"maintenance","version":"0.7.5","language":"javascript","source_language":"en","source_url":"git://github.com/faye/websocket-driver-node","tags":["javascript","websocket"],"install":[{"cmd":"npm install websocket-driver","lang":"bash","label":"npm"},{"cmd":"yarn add websocket-driver","lang":"bash","label":"yarn"},{"cmd":"pnpm add websocket-driver","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for negotiating and using WebSocket extensions (e.g., permessage-deflate). Automatically loaded at runtime.","package":"websocket-extensions","optional":false}],"imports":[{"note":"Default ESM import. CommonJS require() works too but is less idiomatic in modern Node.","wrong":"const websocket = require('websocket-driver')","symbol":"websocket","correct":"import websocket from 'websocket-driver'"},{"note":"Named export for creating a driver from an HTTP request object.","wrong":"import http from 'websocket-driver'","symbol":"http","correct":"import { http } from 'websocket-driver'"},{"note":"Named export for creating a driver in a bare TCP server context.","wrong":"import { Server } from 'websocket-driver'","symbol":"server","correct":"import { server } from 'websocket-driver'"}],"quickstart":{"code":"import http from 'http';\nimport websocket from 'websocket-driver';\n\nconst server = http.createServer();\n\nserver.on('upgrade', (request, socket, body) => {\n  if (!websocket.isWebSocket(request)) return;\n  const driver = websocket.http(request);\n  driver.io.write(body);\n  socket.pipe(driver.io).pipe(socket);\n  driver.messages.on('data', (message) => {\n    console.log('Got a message', message.toString());\n  });\n  driver.start();\n});\n\nserver.listen(8080, () => console.log('Running on 8080'));","lang":"javascript","description":"Shows how to attach a WebSocket driver to an HTTP upgrade event, pipe the socket, and handle incoming messages."},"warnings":[{"fix":"After creating the driver, write the 'body' buffer to driver.io immediately.","message":"Must call driver.io.write(body) before piping the socket to ensure the handshake body is processed.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use driver.messages.on('data', callback) or pipe to another stream.","message":"driver.messages is a stream; you must pipe or listen for 'data' events to receive messages.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Listen for 'connect' on the driver and then call websocket.isWebSocket(driver) to check.","message":"In TCP server mode, the 'connect' event must be used to detect WebSocket requests.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'-75':28 '-76':31 '0.7.5':20 '2020':23 '6455':26 'allow':59 'august':22 'binari':45 'close':48,52 'complet':5 'current':17 'decoupl':54 'detail':56 'draft':27,30 'driver':3 'extens':37,41 'extract':12 'fay':15,86 'faye-websocket':85 'fragment':49 'frame':43 'handl':32 'handshak':33,53 'higher':80 'higher-level':79 'http':62 'http.createserver':64 'i/o':11,58 'implement':8 'javascript':88 'level':76,81 'librari':77,83 'like':84 'low':75 'low-level':74 'mask':50 'messag':42 'modul':69 'negoti':34 'net':68 'ping':46 'pluggabl':10 'pong':47 'project':16 'protocol':7,55 'raw':66 'releas':21 'rfc':25 'select':36 'server':63 'stabl':18 'subprotocol':35 'support':24 'tcp':67 'text':44 'typic':70 'use':60,71 'version':19 'via':38 'websocket':2,6,40,82,87,89 'websocket-driv':1 'websocket-extens':39","created_at":"2026-06-07T17:03:13.939562+00:00","updated_at":"2026-06-07T17:03:13.939562+00:00","problems":[{"fix":"Ensure driver.io.write(body) is called before piping the socket: driver.io.write(body); socket.pipe(driver.io).pipe(socket);","cause":"Calling driver.io.write(body) after socket.pipe(driver.io) may cause the stream to have ended.","error":"Error: write after end"},{"fix":"Verify the driver is created via websocket.http(request) or websocket.server() and that driver.start() is called.","cause":"driver.messages is undefined because the driver hasn't been started yet or was created incorrectly.","error":"TypeError: Cannot read property 'on' of undefined"},{"fix":"Ensure you have imported the module: import websocket from 'websocket-driver' or const websocket = require('websocket-driver').","cause":"Missing import or incorrect import of the module.","error":"ReferenceError: websocket is not defined"}],"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/faye/websocket-driver-node","github":"git://github.com/faye/websocket-driver-node","docs":null,"changelog":null,"pypi":null,"npm":"websocket-driver","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","messaging"],"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}}