Loading…
How I wire up a real-time chat and notification layer on top of a Next.js + Node backend.
Real-time features used to feel like dark magic. With Socket.io and a tiny bit of plumbing, they're now a Tuesday afternoon project.
You have three moving parts:
// server.ts
io.on("connection", (socket) => {
socket.on("message:send", async (payload) => {
const msg = await db.message.create({ data: payload });
io.to(payload.roomId).emit("message:new", msg);
});
});
message:new — flat names rot fast.Real-time isn't really about WebSockets — it's about a clear event vocabulary.