NestJS Server-Sent Events let you stream data from your server to the browser. In this lesson, you learn how to use SSE to push live crypto prices to a Next.js dashboard. You send each update as it comes in.
This stream keeps your charts fresh without a page reload. Your dashboard stays smooth and reacts to new data at once.
What Server-Sent Events Are
SSE is a one‑way stream from your server to the client. The server keeps the connection open. It sends small messages over time.
You use SSE when you need steady updates from the backend but do not need to send data back through the same channel.
Why Use SSE for Crypto Data
Crypto prices change fast. You want to show these changes right away. SSE gives you a simple way to push each price tick to the browser.
This works well for charts, lists, and small UI widgets that need fresh data.
How You Use SSE in NestJS
Create an SSE Endpoint
You build a controller with a route that returns an Observable. Each value you emit becomes an SSE message.
Send Price Updates
Your service can pull new prices from an API or stream. It emits each new value to the controller. The controller forwards it to the client.
How Next.js Reads the Stream
Use the EventSource API
The browser listens to the SSE endpoint with EventSource. It fires an event when the server sends a new message.
Update the Dashboard
Your Next.js page parses each message and updates the chart. This keeps the UI fresh with minimal code.