What if your app could talk to the server instantly, like a live conversation?
Why WebSocket protocol concept in Node.js? - Purpose & Use Cases
Imagine building a chat app where users must refresh the page to see new messages.
Every time you want to get new data, you send a request and wait for a response.
This request-response way is slow and wastes resources because the server can't send updates on its own.
Users see delays and the app feels unresponsive.
WebSocket creates a constant open connection between client and server.
This lets both sides send messages instantly without waiting for requests.
setInterval(() => fetch('/messages').then(response => response.json()).then(data => console.log(data)), 5000);
const ws = new WebSocket('ws://server'); ws.onmessage = e => console.log(e.data);Real-time, two-way communication that feels instant and smooth for users.
Live sports scores updating on your screen without refreshing the page.
Manual polling is slow and inefficient.
WebSocket keeps a live connection open for instant updates.
This improves user experience with real-time data.