{"id":49347,"library":"shocked-server","title":"Shocked WebSocket Server","description":"Shocked is a lightweight WebSocket server library for Node.js (not browser-compatible). Current stable version is 4.0.3, with infrequent releases. It provides a simple API for creating WebSocket servers, handling connections, and managing rooms/groups. Key differentiators: minimal dependencies, native WebSocket API, and built-in room management. However, it lacks advanced features like automatic reconnection or extensive documentation. Suitable for small to medium projects needing basic WebSocket functionality.","status":"active","version":"4.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/sharingapples/shocked/tree/master/packages/server","tags":["javascript"],"install":[{"cmd":"npm install shocked-server","lang":"bash","label":"npm"},{"cmd":"yarn add shocked-server","lang":"bash","label":"yarn"},{"cmd":"pnpm add shocked-server","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Low-level WebSocket implementation. Shocked is a wrapper around ws.","package":"ws","optional":false}],"imports":[{"note":"Server is a named export, not default. In ESM mode, you must use curly braces.","wrong":"import Server from 'shocked-server'","symbol":"Server","correct":"import { Server } from 'shocked-server'"},{"note":"ESM-only since v4. For CommonJS, use import() or upgrade to ESM.","wrong":"const Connection = require('shocked-server').Connection","symbol":"Connection","correct":"import { Connection } from 'shocked-server'"},{"note":"The main class is named Server, not Shocked. Check docs for correct casing.","wrong":"import { Shocked } from 'shocked-server'","symbol":"Server","correct":"import { Server } from 'shocked-server'"}],"quickstart":{"code":"import { Server } from 'shocked-server';\nimport { WebSocketServer } from 'ws'; // not needed directly\n\nconst server = new Server({ port: 8080 });\n\nserver.on('connection', (connection) => {\n  console.log('New connection');\n  connection.on('text', (message) => {\n    console.log('Received:', message);\n    connection.send('Echo: ' + message);\n  });\n});\n\nconsole.log('WebSocket server running on ws://localhost:8080');","lang":"typescript","description":"Creates a WebSocket server on port 8080, echoes incoming text messages."},"warnings":[{"fix":"Convert your project to ESM (use import statements, set 'type':'module' in package.json) or use dynamic import() as a workaround.","message":"In v4.0.0, the package switched from CommonJS to ESM-only. require() calls will fail.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Use the new callback-based API (e.g., connection.on('text', callback)) instead of EventEmitter methods.","message":"The 'Connection' class no longer inherits from EventEmitter. The old event-based API has changed.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Check port availability before creating the server or wrap in try-catch.","message":"Using a port that is already in use will cause the server to throw an 'EADDRINUSE' error. No automatic retry.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use connection.send(string) for text or convert binary to string. For binary, consider using the underlying ws library directly.","message":"The 'send' method with binary data and options object is deprecated since v3.2.0. Use the string overload instead.","severity":"deprecated","affected_versions":">=3.2.0 <4.0.0"}],"env_vars":null,"search_vec":"'4.0.3':21 'advanc':55 'api':29,45 'automat':58 'basic':70 'browser':15 'browser-compat':14 'built':48 'built-in':47 'compat':16 'connect':35 'creat':31 'current':17 'depend':42 'differenti':40 'document':62 'extens':61 'featur':56 'function':72 'handl':34 'howev':52 'infrequ':23 'javascript':73 'key':39 'lack':54 'librari':10 'lightweight':7 'like':57 'manag':37,51 'medium':67 'minim':41 'nativ':43 'need':69 'node.js':12 'project':68 'provid':26 'reconnect':59 'releas':24 'room':50 'rooms/groups':38 'server':3,9,33 'shock':1,4 'simpl':28 'small':65 'stabl':18 'suitabl':63 'version':19 'websocket':2,8,32,44,71","created_at":"2026-06-07T17:01:17.651781+00:00","updated_at":"2026-06-07T17:01:17.651781+00:00","problems":[{"fix":"Change to import syntax or use dynamic import(). Example: const { Server } = await import('shocked-server');","cause":"Using require() to import shocked-server v4 which is ESM-only.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module not supported"},{"fix":"Use named import: import { Server } from 'shocked-server'","cause":"Incorrect import: trying to use default import (import Server from ...) instead of named import.","error":"TypeError: Server is not a constructor"},{"fix":"Install ws: npm install ws","cause":"Missing peer dependency 'ws' when using shocked-server.","error":"Error [ERR_MODULE_NOT_FOUND]: Cannot find module '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/sharingapples/shocked/tree/master/packages/server","github":"https://github.com/sharingapples/shocked/tree/master/packages/server","docs":null,"changelog":null,"pypi":null,"npm":"shocked-server","openapi_spec":null,"status_page":null,"smithery":null,"categories":["communication"],"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}}