you can use a html template having an div with a specific id that will contain chat messages.
Now you can use any websocket library like mqtt, socket.io, websocket etc to get real-time data.
So when you get any new message you can add that message using JavaScript append function.