Skip to content

SSE (Sever Side Events): Simple example using Node JS

Notifications You must be signed in to change notification settings

brysonbw/node-sse-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SSE (Sever-Side-Events): Simple Example Using Node JS

Install

npm install

Start Server

npm run dev

What is SSE (Sever-Side-Events)

A one-way connection, the server sending data to the client.

Server/Response sends the ‘text’ through the headers to client

Node JS Example:

app.use('/stream', (req, res) => {
res.setHeader('Content-Type', 'text/event-stream')
res.write('data: ' + '<ENTER_YOUR_DATA_TO_SEND>\n\n')
})

SSE (Server-Side-Events) Components

  • HTTP 1 and/or HTTP 2

Reciving Events From The Server (Client-Side)

The server-sent event (browser) API is contained in the EventSource interface.

About

SSE (Sever Side Events): Simple example using Node JS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published