Q33: How do Server-Sent Events (SSE) work in Node.js and how do they differ from WebSockets?

Server-Sent Events (SSE) provide unidirectional real-time text streaming from server to client over standard HTTP using the text/event-stream content type. Unlike WebSockets, which are full-duplex TCP connections, SSE runs over standard HTTP, includes native automatic client reconnection, and works seamlessly with standard HTTP proxies and load balancers.

Key Takeaways
  • SSE enables single-direction text streaming using the standard text/event-stream MIME type.
  • WebSockets provide bidirectional TCP messaging, whereas SSE simplifies server-to-client updates over HTTP.
Knowledge Check

Which HTTP Content-Type header must a Node.js response set to stream Server-Sent Events?