Websockets, Programming, Examples

Implementing a “Hello World” WebSocket App on Heroku

Quick and easy, and with numerous potential applications.

My AI (Midjourney) prompt was for two cats to be talking on an old-school / primitive telephone made of tin cans. But, I kind of liked this image, anyway, so I’ve used it here. Midjourney AI continues to fascinate me!

Lately, I’ve been thinking a lot about persistent, realtime, bidirectional communications in apps. This all started around a month ago when I was building out a messaging system for a React project I’m a team member on. I hadn’t at the time envisioned that we needed realtime communication and so, when that spec came into play, I thought I was going to have to refactor almost everything.

We’d been using Google Firebase / Firestore and, as luck would have it, they have a workable solution built in. It’s called their onSnapshot() method. I was surprised at how easy it was to get working, by the way. I merely updated my main query that fetches message and, boom, the app updated itself in realtime.

I got lucky there, of course. But when I think of realtime communications within apps, I often think of using WebSockets — something that I’ve known many devs to struggle with, as the server configuration aspect always seemed to give them troubles.

Out of curiosity, I went poking around myself and found Heroku which, to make a long story short, seemed to be a pretty great place to play around with WebSockets. (I’m not affiliated with Heroku, btw. Just…

--

--