A lightweight WebSocket server implementation for Node.js. Version 2.4.2 is the latest stable release, with infrequent updates. Provides a simple event-driven API for handling WebSocket connections, supporting both direct server listening and sharing a port with an existing HTTP server via the `leech` method. Key differentiators: minimalistic design, explicit listener object pattern, and support for both direct and piggyback server modes. No external dependencies.
npm install madsocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows complete setup: create server instance with event listeners, start listening on port 8080, handle messages and errors, and graceful shutdown.
Pass listeners as first argument, props as second. Remove port from constructor; use .listen() instead.
For Node <10, attach leech to 'upgrade' event: `server.on('upgrade', (req, socket) => ws.leech(req, socket))`.Choose one approach: either use 'connection' event for Node v10+ or 'upgrade' event for older versions, not both.
Set timeout to a positive number (milliseconds) to auto-close idle sockets.
Use regular functions (not arrow functions) for listeners to access ClientConnection via 'this'.
Use `import MadSocket from 'madsocket'` instead of `import { MadSocket } from 'madsocket'`Replace arrow function with regular function: `message: function(msg) { ... }`Choose a different port or kill the process using the port
Upgrade to madsocket@2.4.2
No dependency data recorded yet.