Registry / messaging / imock-socket

imock-socket

JSON →
library0.0.28jsnpmunverified

iMock Socket is a WebSocket cluster server and client library that combines Socket.IO with Redis for horizontal scaling. The current stable version is 0.0.28, released with a moderate cadence. It differentiates by offering a lightweight abstraction over Socket.IO with built-in Redis pub/sub for multi-server setups, making it suitable for real-time applications that need to scale across multiple nodes. It supports both server and client roles, integrates easily with Express, and is designed for Node.js 8.8+.

npm install imock-socket
INSTALL
IMPORT
SIG · IMOCK-SOCKET
I
imock-socket
messagingjavascriptv0.0.28
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.

default
import iMockSocket from 'imock-socket'
const iMockSocket = require('imock-socket')
ESM import; CJS require works but may lack type definitions.
Server
import { Server } from 'imock-socket'
Named export for creating a server instance.
Client
import { Client } from 'imock-socket'
Named export for creating a client instance.

Sets up an iMock Socket server with Express and Redis, listens for connections, and demonstrates a basic echo response. Also shows client-side usage.

import iMockSocket from 'imock-socket'; import express from 'express'; import redis from 'redis'; const app = express(); const server = app.listen(3000); const redisClient = redis.createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' }); const imock = iMockSocket({ server, redis: redisClient }); // Server imock.server.on('connection', (socket) => { console.log('Client connected'); socket.on('message', (data) => { console.log('Received:', data); socket.emit('response', `Echo: ${data}`); }); }); // Client (optional, in separate process) const client = iMockSocket({}); client.client.on('connect', () => { client.client.emit('message', 'Hello from client'); });
Debug
Known issues
gotchaThe package is version 0.0.x and may have breaking changes in minor versions.
fix
Pin to exact version in package.json.
affects: >=0.0.0
breakingRequires Node.js >=8.8 and npm >=6; older versions may fail.
fix
Upgrade Node.js to 8.8+.
affects: <8.8
deprecatedThe package uses an older version of Socket.IO; newer versions may have breaking changes.
fix
Check Socket.IO compatibility.
affects: >=0.0.0
gotchaRedis is required for cluster mode; missing Redis connection causes silent failures.
fix
Ensure Redis is running and URL is correct.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Redis connection to localhost:6379 failed
Redis server not running or url incorrect
fix
Start Redis or set REDIS_URL env variable.
TypeError: Cannot read property 'emit' of undefined
Client connection not established before emitting
fix
Wrap emits inside 'connect' event listener.
ReferenceError: require is not defined
Using require in ESM context
fix
Use import statements or set type: 'module' in package.json and use .mjs extension.
Upgrade
Version history
0.0.28latest on npm
Audit
Dependencies
socket.iorequiredCore WebSocket transport
socket.io-clientrequiredClient-side WebSocket connection
redisrequiredPub/sub for cluster communication
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
imock-socket — npm install imock-socket · libregistry