Registry / communication / shocked-server

shocked-server

JSON →
library4.0.3jsnpmunverified

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.

npm install shocked-server
INSTALL
IMPORT
SIG · SHOCKED-SERVER
S
shocked-server
communicationjavascriptv4.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Server
import { Server } from 'shocked-server'
import Server from 'shocked-server'
Server is a named export, not default. In ESM mode, you must use curly braces.
Connection
import { Connection } from 'shocked-server'
const Connection = require('shocked-server').Connection
ESM-only since v4. For CommonJS, use import() or upgrade to ESM.
Server
import { Server } from 'shocked-server'
import { Shocked } from 'shocked-server'
The main class is named Server, not Shocked. Check docs for correct casing.

Creates a WebSocket server on port 8080, echoes incoming text messages.

import { Server } from 'shocked-server'; import { WebSocketServer } from 'ws'; // not needed directly const server = new Server({ port: 8080 }); server.on('connection', (connection) => { console.log('New connection'); connection.on('text', (message) => { console.log('Received:', message); connection.send('Echo: ' + message); }); }); console.log('WebSocket server running on ws://localhost:8080');
Debug
Known issues
breakingIn v4.0.0, the package switched from CommonJS to ESM-only. require() calls will fail.
fix
Convert your project to ESM (use import statements, set 'type':'module' in package.json) or use dynamic import() as a workaround.
affects: >=4.0.0
breakingThe 'Connection' class no longer inherits from EventEmitter. The old event-based API has changed.
fix
Use the new callback-based API (e.g., connection.on('text', callback)) instead of EventEmitter methods.
affects: >=4.0.0
gotchaUsing a port that is already in use will cause the server to throw an 'EADDRINUSE' error. No automatic retry.
fix
Check port availability before creating the server or wrap in try-catch.
affects: >=0.0.0
deprecatedThe 'send' method with binary data and options object is deprecated since v3.2.0. Use the string overload instead.
fix
Use connection.send(string) for text or convert binary to string. For binary, consider using the underlying ws library directly.
affects: >=3.2.0 <4.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using require() to import shocked-server v4 which is ESM-only.
fix
Change to import syntax or use dynamic import(). Example: const { Server } = await import('shocked-server');
TypeError: Server is not a constructor
Incorrect import: trying to use default import (import Server from ...) instead of named import.
fix
Use named import: import { Server } from 'shocked-server'
Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'ws'
Missing peer dependency 'ws' when using shocked-server.
fix
Install ws: npm install ws
Upgrade
Version history
4.0.3latest on npm
Audit
Dependencies
wsrequiredLow-level WebSocket implementation. Shocked is a wrapper around ws.
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
1
Resources
shocked-server — npm install shocked-server · libregistry