{"id":48178,"library":"imock-socket","title":"iMock Socket","description":"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+.","status":"active","version":"0.0.28","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install imock-socket","lang":"bash","label":"npm"},{"cmd":"yarn add imock-socket","lang":"bash","label":"yarn"},{"cmd":"pnpm add imock-socket","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core WebSocket transport","package":"socket.io","optional":false},{"reason":"Client-side WebSocket connection","package":"socket.io-client","optional":false},{"reason":"Pub/sub for cluster communication","package":"redis","optional":false}],"imports":[{"note":"ESM import; CJS require works but may lack type definitions.","wrong":"const iMockSocket = require('imock-socket')","symbol":"default","correct":"import iMockSocket from 'imock-socket'"},{"note":"Named export for creating a server instance.","symbol":"Server","correct":"import { Server } from 'imock-socket'"},{"note":"Named export for creating a client instance.","symbol":"Client","correct":"import { Client } from 'imock-socket'"}],"quickstart":{"code":"import iMockSocket from 'imock-socket';\nimport express from 'express';\nimport redis from 'redis';\n\nconst app = express();\nconst server = app.listen(3000);\nconst redisClient = redis.createClient({ url: process.env.REDIS_URL ?? 'redis://localhost:6379' });\n\nconst imock = iMockSocket({ server, redis: redisClient });\n\n// Server\nimock.server.on('connection', (socket) => {\n  console.log('Client connected');\n  socket.on('message', (data) => {\n    console.log('Received:', data);\n    socket.emit('response', `Echo: ${data}`);\n  });\n});\n\n// Client (optional, in separate process)\nconst client = iMockSocket({});\nclient.client.on('connect', () => {\n  client.client.emit('message', 'Hello from client');\n});","lang":"javascript","description":"Sets up an iMock Socket server with Express and Redis, listens for connections, and demonstrates a basic echo response. Also shows client-side usage."},"warnings":[{"fix":"Pin to exact version in package.json.","message":"The package is version 0.0.x and may have breaking changes in minor versions.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade Node.js to 8.8+.","message":"Requires Node.js >=8.8 and npm >=6; older versions may fail.","severity":"breaking","affected_versions":"<8.8"},{"fix":"Check Socket.IO compatibility.","message":"The package uses an older version of Socket.IO; newer versions may have breaking changes.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Ensure Redis is running and URL is correct.","message":"Redis is required for cluster mode; missing Redis connection causes silent failures.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.0.28':26 '8.8':83 'abstract':38 'across':64 'applic':59 'built':43 'built-in':42 'cadenc':31 'client':11,72 'cluster':8 'combin':14 'current':22 'design':80 'differenti':33 'easili':75 'express':77 'horizont':19 'imock':1,3 'integr':74 'javascript':84 'librari':12 'lightweight':37 'make':52 'moder':30 'multi':49 'multi-serv':48 'multipl':65 'need':61 'node':66 'node.js':82 'offer':35 'pub/sub':46 'real':57 'real-tim':56 'redi':17,45 'releas':27 'role':73 'scale':20,63 'server':9,50,70 'setup':51 'socket':2,4 'socket.io':15,40 'stabl':23 'suitabl':54 'support':68 'time':58 'version':24 'websocket':7","created_at":"2026-06-07T16:55:18.324498+00:00","updated_at":"2026-06-07T16:55:18.324498+00:00","problems":[{"fix":"Start Redis or set REDIS_URL env variable.","cause":"Redis server not running or url incorrect","error":"Error: Redis connection to localhost:6379 failed"},{"fix":"Wrap emits inside 'connect' event listener.","cause":"Client connection not established before emitting","error":"TypeError: Cannot read property 'emit' of undefined"},{"fix":"Use import statements or set type: 'module' in package.json and use .mjs extension.","cause":"Using require in ESM context","error":"ReferenceError: require 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":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"imock-socket","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging","devops"],"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}}