node.jsserver-sent-eventssveltekit

How can I implement server sent events (SSE) in SvelteKit?


I can't find a tutorial for SvelteKit without using custom express server. Are there any alternatives with an API endpoint?

I've tried setting up the API endpoint myself, but I can't make it send an update when the data changes.


Solution

  • You would probably have to return a ReadableStream that you can write the updates to. That way the connection is not closed.

    As of now there is an open issue regarding more documentation on this.