DEV Community

Mohamed Ibrahim
Mohamed Ibrahim

Posted on

πŸ’¬ How to Build a Real-Time Chat App from Scratch with Node.js + Socket.IO

Have you ever wanted to build your own real-time chat app from scratch? In this post, I’ll show you how I built a simple and clean chat application using Node.js, Socket.IO, and a frontend built with HTML/CSS/JavaScript β€” no database required (at least for now πŸ˜‰).


πŸ”§ Technologies Used

  • Node.js + Express β€” backend server
  • Socket.IO β€” real-time communication (WebSockets)
  • HTML + CSS (Dark theme) β€” GitHub-like dark mode
  • Vanilla JavaScript β€” frontend logic

πŸ–ΌοΈ App Preview

Users join a room by entering their name, and immediately join the live chat. Messages appear on the right for your own messages, and on the left for others. You’ll also see join/leave system notifications.


πŸ“¦ Project Structure

/public
  β”œβ”€β”€ index.html     # Join page (username input)
  β”œβ”€β”€ chat.html      # Main chat interface
  β”œβ”€β”€ styles.css     # Custom dark styling
  └── script.js      # Handles socket and UI logic

server.js            # Node.js server + Socket.IO logic
Enter fullscreen mode Exit fullscreen mode

πŸš€ How to Run Locally

  1. Clone the repository:
git clone https://github.com/Mo-Ibra/simple-chat-app
cd your-repo-name
Enter fullscreen mode Exit fullscreen mode
  1. Install dependencies:
npm install
Enter fullscreen mode Exit fullscreen mode
  1. Start the server:
node server.js
Enter fullscreen mode Exit fullscreen mode
  1. Open in browser:
http://localhost:3000
Enter fullscreen mode Exit fullscreen mode

πŸ’‘ Features

  • βœ… Real-time messaging between users
  • βœ… Notifications when users join/leave
  • βœ… Messages styled to indicate sender
  • βœ… Logout button that redirects to the join screen
  • βœ… No backend database needed for now (session-based)

πŸ”’ No Database? No Problem

At this stage, all messages are held temporarily in memory and disappear on refresh. In the future, you can easily plug in MongoDB, PostgreSQL, or any database to persist data.


πŸ“ Want the Code?

Here’s the GitHub repo:

πŸ”— Mo-Ibra/simple-chat-app


πŸ’¬ Final Thoughts

This was a great exercise to understand WebSocket communication and Socket.IO in a very hands-on way. It’s perfect for beginners who want to get a feel for real-time apps.

Feel free to fork the project, add new features like emojis, typing indicators, private messaging, or even a database backend!


Thanks for reading! ❀️

If you found this useful, give it a ❀️ or leave a comment below.

Top comments (0)