Day 168 of Learning MERN Stack

์ž‘์„ฑ์ž

์นดํ…Œ๊ณ ๋ฆฌ:

โ† ํ”ผ๋“œ๋กœ
DEV Community ยท Ali Hamza ยท 2026-08-01 ๊ฐœ๋ฐœ(SW)

Ali Hamza

Hello Dev Community! ๐Ÿ‘‹

It is officially Day 168 of my full-stack web development journey! Today, I established the real-time websocket foundation and cloud storage helper utilities for QuickChat using Socket.io, Express, and Cloudinary! โšกโš™๏ธ

๐Ÿ› ๏ธ Technical Breakdown: Sockets & Cloud Infrastructure

As captured in my implementation snapshots (Screenshots 411 & 412):

1. Real-time Socket Server Module (socket.js)

  • Configured Socket.io server instance with CORS origin wildcarding.
  • Maintained an in-memory userSocketMap object linking authenticated userId instances to active socket session identifiers (socket.id).
  • Implemented live online user broadcasting (getOnlineUser) across client connections:

javascript
  io.on('connection', (socket) => {
    const userId = socket.handshake.query.userId;
    if (userId) userSocketMap[userId] = socket.id;

    io.emit('getOnlineUser', Object.keys(userSocketMap));

    socket.on('disconnect', () => {
      delete userSocketMap[userId];
      io.emit('getOnlineUser', Object.keys(userSocketMap));
    });
  });

Enter fullscreen mode Exit fullscreen mode

์›๋ฌธ์—์„œ ๊ณ„์† โ†—

์ถ”์ถœ ๋ณธ๋ฌธ ยท ์ถœ์ฒ˜: dev.to ยท https://dev.to/ali_hamza_589ec7b3eb6688d/day-168-of-learning-mern-stack-3ng0

์ฝ”๋ฉ˜ํŠธ

๋‹ต๊ธ€ ๋‚จ๊ธฐ๊ธฐ

์ด๋ฉ”์ผ ์ฃผ์†Œ๋Š” ๊ณต๊ฐœ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ํ•„์ˆ˜ ํ•„๋“œ๋Š” *๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค