Request for sample NodeJS app implementing SSE

I want to write a NodeJS-based application that uses Server Sent Events (SSEs) to listen to events published by Spark Cores. I want the application to record the events it hears in a data store e.g. MySQL or MongoDB. I’d like to use Heroku to host the application and data store.

Has anyone written a similar application? If so I’d really appreciate it if you shared your code and learnings.

Does the thread ( answer your question? If not, let me know what I misunderstood and I’ll try to help!

Sorry harrisonhjones, I wasn’t paying close enough attention to the other thread. Yeah that’s exactly what I needed.

For other readers, harrisonhjones has a great example of a NodeJS code listening to Spark Core events and writing them to a MySQL database here:

harrisonhjones: Tiny thing, maybe fix the mismatched quotations on this line in your example?
console.log("Listening for events’);
Just for clarity. Thanks again.

I’m glad I was able to help!

Thanks for the error find. I’ve updated the gist to fix the mistake

Did you get your NodeJS working with MongoDB?

Hi harrisonhjones.

In the end I decided to go with MySQL as I am more familiar with it than MongoDB. So it was quicker for me to get it up and running. Took me a solid 12 hours work to go from signing up to Heroku to having the stuff detailed below working. Lots of learnings on the way.

For the past week I’ve had my Core publishing events on household temperature every 15, with a NodeJS script running on the Heroku platform listening to those events and recording them in a MySQL database. A website running on Heroku gives summary information on the events.

Only problem I’ve had is my household internet connection which is intermittently flaky. When connectivity is poor, the core can’t connect to the cloud, and so Heroku stops hearing events, and after an hour Heroku goes into sleep mode and does not re-awaken when the core starts publishing events again. Still need to fix this.

1 Like