Posts List

Live Process Output To The User With Redis and Server-Sent Events

In a recent project I needed to collect the output from a process that was occurring on the server and output it to the user on the frontend. Ideally that would occur in nearly real time. The process I needed to collect output from is a third-party library that outputs everything to STDOUT or STDERR. The easiest way for me to accomplish that without shenanigans was to create a module to run the library and then fork the module as a child process and then pipe the output to a stream handler.

Server-Sent Events With Node

Server-Sent Events (SSEs) allow one-way communication from the server to the client. They can be very useful for things like notifications or activity feeds. I’ve recently used them in a project to display output from a background process in the browser. In the browser, you connect to the server using the EventSource interface and just add event listeners. It is really very easy. const sseSource = new EventSource('/event-stream'); sseSource.addEventListener('message', (e) => { const messageData = e.