Menu

What Is WebSockets? Build a Real-Time Chat Server with Express, NestJS, and MongoDB
πŸ“°

What Is WebSockets? Build a Real-Time Chat Server with Express, NestJS, and MongoDB

DEV Community: mongodbΒ·Muhammad Hamid RazaΒ·2 days ago
#aCtZ53uV
#devtomongodb#devto#dev#socket#chat
Long article (2635 words) β€” no AI summary yet.
Reading 0:00
15s threshold

You send a chat message and wait. Nothing happens. You refresh the page, and there it is, three messages late. πŸ˜…

That's what happens when a "live" feature is built on plain HTTP alone. The browser has to keep asking, "Anything new yet?" That's slow, wasteful, and a little embarrassing.

So how do apps like chats, live dashboards, and multiplayer games update instantly? Most of them use WebSockets . In this post, you'll learn what WebSockets are and build the same real-time chat server twice, once with Express and once with NestJS , saving messages in MongoDB . πŸš€

What Is WebSockets?

WebSockets is a way for a browser and a server to keep one connection open and talk to each other at any time.

Think of regular HTTP like sending letters. You write a letter (request), the server writes back (response), and the conversation ends. If you want more, you send another letter.

A WebSocket is more like a phone call .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.