awesome-scalability
The Patterns of Scalable, Reliable, and Performant Large-Scale Systems
- 76k
- MIT
- 11 mo ago
Complete Socket.IO guide with practical real-time communication examples.
Repo elyse502/node-socket.io, read from GitHub 1 min ago. elyse502 has not joined Take My Repo.
elyse502/node-socket.io is a public repo on GitHub by elyse502. Complete Socket.IO guide with practical real-time communication examples. It declares the MIT license on GitHub. It is written mainly in JavaScript, has 1 stars and last changed on 2026-05-19. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-22.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
This project is a comprehensive learning exploration of Socket.IO, the leading library for real-time, bidirectional, event-based communication between web clients and servers. Built from scratch, it demonstrates how to create interactive applications with persistent connections, real-time data exchange, and instant event handling.
| Feature | Traditional HTTP | Socket.IO |
|---|---|---|
| Connection | Request-response, stateless | Persistent, stateful |
| Communication | One-way (client โ server) | Bidirectional (client โ server) |
| Real-time | Polling required | Native real-time |
| Overhead | High per request | Low per message |
| Latency | High (new connection each time) | Low (persistent connection) |
| Use Cases | REST APIs, page loads | Chat, gaming, live updates |
| Category | Feature | Status |
|---|---|---|
| Connection Management | Real-time persistent connections | โ |
| Event System | Custom event emission and handling | โ |
| Message Broadcasting | Send messages to all connected clients | โ |
| Room Management | Group clients into logical rooms | โ |
| Namespace Support | Isolated communication channels | โ |
| Disconnect Handling | Automatic cleanup on client disconnect | โ |
| Error Recovery | Automatic reconnection with backoff | โ |
| Multiple Clients | Handle concurrent connections | โ |
| Server Events | Emit events from server to clients | โ |
| Client Events | Emit events from clients to server | โ |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ CLIENT LAYER (Browser) โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ Socket.IO Client Library โ โ โ โ โข Establishes WebSocket connection โ โ โ โ โข Manages reconnection logic โ โ โ โ โข Emits and listens to events โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ UI Components โ โ โ โ โข Event displays โ โ โ โ โข Message input forms โ โ โ โ โข Connection status indicators โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ WebSocket / HTTP Long-Polling โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ SERVER LAYER (Node.js) โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ HTTP Server โ โ โ โ โข Serves static files (HTML, CSS, JS) โ โ โ โ โข Handles initial page loads โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ Socket.IO Server โ โ โ โ โข Manages all client connections โ โ โ โ โข Handles event routing โ โ โ โ โข Manages rooms and namespaces โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ Event Handlers โ โ โ โ โข connection: New client joined โ โ โ โ โข message: User sent message โ โ โ โ โข disconnect: Client left โ โ โ โ โข custom-event: Application-specific logic โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Technology | Version | Purpose | Badge |
|---|---|---|---|
| Node.js | 18+ | JavaScript Runtime | |
| Express.js | 4.x | Web Framework | |
| Socket.IO | 4.x | Real-time Engine | |
| HTML5 | - | Structure | |
| JavaScript | ES6+ | Client Logic |
node-socket.io/ โ โโโ ๐ client/ # Frontend application โ โโโ ๐ index.html # Main UI page โ โโโ ๐ script.js # Active client logic โ โโโ ๐ script_0.js # Learning iteration 0 โ โโโ ๐ script_1.js # Learning iteration 1 โ โโโ ๐ package.json # Client dependencies โ โโโ ๐ package-lock.json # Locked dependencies โ โโโ ๐ server/ # Backend application โ โโโ ๐ server.js # Active server logic โ โโโ ๐ server_0.js # Learning iteration 0 โ โโโ ๐ server_1.js # Learning iteration 1 โ โโโ ๐ server_2.js # Learning iteration 2 โ โโโ ๐ package.json # Server dependencies โ โโโ ๐ package-lock.json # Locked dependencies โ โโโ ๐ .gitignore # Git ignore rules โโโ ๐ README.md # Documentation
| File | Topic Covered |
|---|---|
server_0.js / script_0.js |
Basic connection establishment |
server_1.js / script_1.js |
Event emission and handling |
server_2.js / script_2.js |
Broadcasting and rooms |
# 1. Clone the repository git clone https://github.com/elyse502/node-socket.io.git # 2. Navigate to project directory cd node-socket.io # 3. Install server dependencies cd server npm install # 4. Install client dependencies (if any) cd ../client npm install # 5. Return to root directory cd ..
# Start the server (from server directory) cd server npm run devStart # OR for development with auto-reload nodemon server.js # Open browser and navigate to http://localhost:3000
# Development mode (with auto-restart) npm run dev # Production mode npm start # Alternative port (modify server.js) PORT=8080 npm start
// Server const io = require("socket.io")(server); io.on("connection", (socket) => { console.log("New client connected:", socket.id); }); // Client const socket = io("http://localhost:3000"); socket.on("connect", () => { console.log("Connected to server"); });
// Client to Server socket.emit("message", { text: "Hello Server!" }); // Server to Client socket.emit("welcome", { message: "Welcome to the chat!" }); // Server to All Clients (Broadcast) io.emit("announcement", { text: "New user joined!" });
// Server socket.on("message", (data) => { console.log("Received:", data); // Process and possibly respond }); // Client socket.on("welcome", (data) => { console.log("Server says:", data.message); });
// Server socket.on("disconnect", (reason) => { console.log("Client disconnected:", socket.id, "Reason:", reason); }); // Client socket.on("disconnect", (reason) => { console.log("Disconnected from server:", reason); });
// Send to all clients except sender socket.broadcast.emit("user-joined", { userId: socket.id }); // Send to all clients including sender io.emit("global-update", { status: "active" }); // Send to specific room io.to("room1").emit("room-message", { text: "Hello Room 1!" });
โโโโโโโโโโโโ โโโโโโโโโโโโ
โ Client โ โ Server โ
โ A โ โ โ
โโโโโโฌโโโโโโ โโโโโโฌโโโโโโ
โ โ
โ 1. socket.emit('message', data) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ>โ
โ โ
โ โ 2. Process message
โ โ Save to DB
โ โ Broadcast to others
โ โ
โ 3. socket.broadcast.emit('message', data) โ
โ<โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ 4. socket.on('message', handler) โ
โ Display message โ
โ โ
โ 5. User disconnects โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ>โ
โ โ
โ 6. io.emit('user-left', userId) โ
โ<โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ 7. Update UI - remove user โ
โ โ
// Monitor connection state socket.on("connect", () => { updateStatus("Connected", "green"); }); socket.on("disconnect", () => { updateStatus("Disconnected", "red"); }); socket.on("connect_error", (error) => { updateStatus("Connection Error", "orange"); });
// Socket.IO handles reconnection automatically // Configure reconnection options const socket = io({ reconnection: true, reconnectionAttempts: 5, reconnectionDelay: 1000, reconnectionDelayMax: 5000, });
<!-- Sample HTML Structure --> <div id="messages"> <div class="message received"> <strong>User:</strong> Hello! <small>10:30 AM</small> </div> </div> <input type="text" id="messageInput" placeholder="Type a message..." /> <button onclick="sendMessage()">Send</button>
const io = require("socket.io")(server, { cors: { origin: "http://localhost:3000", methods: ["GET", "POST"], }, }); // Track connected users const users = new Map(); io.on("connection", (socket) => { users.set(socket.id, { id: socket.id, joinedAt: Date.now() }); console.log(`Total users: ${users.size}`); socket.on("disconnect", () => { users.delete(socket.id); console.log(`Total users: ${users.size}`); }); });
// Join a room socket.on("join-room", (roomName) => { socket.join(roomName); socket.to(roomName).emit("user-joined", socket.id); }); // Leave a room socket.on("leave-room", (roomName) => { socket.leave(roomName); socket.to(roomName).emit("user-left", socket.id); }); // Send to room socket.to("chat-room").emit("message", data);
Server (server.js):
const express = require("express"); const http = require("http"); const socketIo = require("socket.io"); const app = express(); const server = http.createServer(app); const io = socketIo(server); app.use(express.static("client")); io.on("connection", (socket) => { console.log("User connected:", socket.id); // Broadcast to others that user joined socket.broadcast.emit("user-joined", socket.id); // Handle incoming messages socket.on("chat-message", (message) => { // Broadcast message to all clients io.emit("chat-message", { userId: socket.id, text: message, timestamp: new Date().toISOString(), }); }); socket.on("disconnect", () => { console.log("User disconnected:", socket.id); io.emit("user-left", socket.id); }); }); server.listen(3000, () => { console.log("Server running on port 3000"); });
Client (script.js):
const socket = io(); // DOM elements const messageForm = document.getElementById("message-form"); const messageInput = document.getElementById("message-input"); const messagesDiv = document.getElementById("messages"); // Send message messageForm.addEventListener("submit", (e) => { e.preventDefault(); const message = messageInput.value; if (message) { socket.emit("chat-message", message); messageInput.value = ""; } }); // Receive message socket.on("chat-message", (data) => { const messageElement = document.createElement("div"); messageElement.className = "message"; messageElement.innerHTML = ` <strong>${data.userId}</strong> <span>${data.text}</span> <small>${new Date(data.timestamp).toLocaleTimeString()}</small> `; messagesDiv.appendChild(messageElement); messagesDiv.scrollTop = messagesDiv.scrollHeight; }); // User joined/left notifications socket.on("user-joined", (userId) => { addSystemMessage(`User ${userId} joined the chat`); }); socket.on("user-left", (userId) => { addSystemMessage(`User ${userId} left the chat`); });
const io = socketIo(server, { // CORS settings cors: { origin: "*", methods: ["GET", "POST"], credentials: true, }, // Transport options transports: ["websocket", "polling"], // Connection options pingTimeout: 60000, pingInterval: 25000, // Upgrade options allowUpgrades: true, upgradeTimeout: 10000, // Cookie options cookie: { name: "io", httpOnly: true, sameSite: "lax", }, });
const socket = io({ // Connection URL path: "/socket.io", // Transport options transports: ["websocket", "polling"], // Reconnection options reconnection: true, reconnectionAttempts: Infinity, reconnectionDelay: 1000, reconnectionDelayMax: 5000, // Timeout options timeout: 20000, // Query parameters query: { token: "your-auth-token", userId: "123", }, // Authentication auth: { token: "your-jwt-token", }, });
# Terminal 1 - Start server cd server npm run devStart # Terminal 2 - Open first client open http://localhost:3000 # Terminal 3 - Open second client (incognito/private window) open http://localhost:3000
# Use wscat for WebSocket testing npm install -g wscat wscat -c ws://localhost:3000/socket.io/?EIO=4&transport=websocket
// Enable debug logging localStorage.debug = 'socket.io-client:*'; // Or in Node.js DEBUG=socket.io:* node server.js
| Issue | Solution |
|---|---|
| Connection refused | Check if server is running on correct port |
| CORS errors | Configure CORS options in server |
| Connection drops | Increase pingTimeout and pingInterval |
| Messages not received | Check event names match exactly |
| Multiple connections | Ensure socket.io client imported only once |
| Reconnection not working | Check reconnection options configuration |
| Large messages failing | Implement message chunking or increase limits |
| Aspect | Recommendation | Why |
|---|---|---|
| Message Size | Keep < 10KB | Large messages fragment and increase latency |
| Event Frequency | Limit to < 100/sec | Too many events overwhelm the connection |
| Connected Clients | Scale horizontally | Single server handles ~10,000 connections |
| Rooms | Clean up empty rooms | Prevents memory leaks |
| Binary Data | Use binary transfers | More efficient for images/files |
| Compression | Enable per-message deflate | Reduces bandwidth usage |
// Use Redis adapter for multiple server instances const redisAdapter = require("@socket.io/redis-adapter"); const redis = require("redis"); const pubClient = redis.createClient(); const subClient = pubClient.duplicate(); io.adapter(redisAdapter(pubClient, subClient));
| Topic | Description | Difficulty |
|---|---|---|
| Namespaces | Separate communication channels | โญโญ |
| Rooms | Group-based messaging | โญโญ |
| Acknowledgements | Confirmation of message receipt | โญโญโญ |
| Middleware | Authentication and logging | โญโญโญ |
| Redis Adapter | Horizontal scaling | โญโญโญโญ |
| Binary Streaming | File and data streaming | โญโญโญโญ |
| Custom Parsers | Optimize data serialization | โญโญโญโญโญ |
Junior Fullstack Software Engineer
This project is licensed under the MIT License - see the LICENSE file for details.
Built with ๐ป, WebSockets, and Real-Time Passion
From basic connections to production-ready real-time applications - this is your complete Socket.IO learning journey!
elyse502/node-socket.io is a public repo on GitHub by elyse502. Complete Socket.IO guide with practical real-time communication examples.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-05-19. GitHub counts 0 open issues and pull requests. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
The Patterns of Scalable, Reliable, and Performant Large-Scale Systems
Dapr is a portable runtime for building distributed applications across cloud and edge, combining event-driven architecture with workflow orchestration.

โ The Node.js best practices list (July 2026)
Flutter makes it easy and fast to build beautiful apps for mobile and beyond
f.k.a. Awesome ChatGPT Prompts. Share, discover, and collect prompts from the community. Free and open source โ self-host for your organization with complete privacy.
Full Stack AI SaaS App using React js | Complete PERN Stack Project

Full Stack DeepSeek Clone Using Next JS With DeepSeek API | AI Project In Next Js

This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/elyse502/node-socket.ioTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.