Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucasgdb/node-sse-example
Server-Sent Events example in Node.js
https://github.com/lucasgdb/node-sse-example
curl docker monorepo node react server-sent-events sse typescript
Last synced: 2 months ago
JSON representation
Server-Sent Events example in Node.js
- Host: GitHub
- URL: https://github.com/lucasgdb/node-sse-example
- Owner: lucasgdb
- Created: 2022-07-23T15:34:19.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-07-24T20:00:07.000Z (over 2 years ago)
- Last Synced: 2024-04-18T07:13:19.201Z (9 months ago)
- Topics: curl, docker, monorepo, node, react, server-sent-events, sse, typescript
- Language: TypeScript
- Homepage:
- Size: 239 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Server-Sent Events (SSE)
Server-Sent Events (SSE) is a [server push](https://en.wikipedia.org/wiki/Push_technology) technology enabling a client to receive automatic updates from a server via an HTTP connection, and describes how servers can initiate data transmission towards clients once an initial client connection has been established. They are commonly used to send message updates or continuous data streams to a browser client and designed to enhance native, cross-browser streaming through a JavaScript API called EventSource, through which a client requests a particular URL in order to receive an event stream. The EventSource API is standardized as part of HTML5 by the WHATWG. The mime type for SSE is text/event-stream.
## Requirements
- Docker
- cURL### Development
- `yarn`: Installs all needed dependencies
- `yarn dev`: Starts the project in development mode
- Open at `http://localhost:8080`
- `yarn stop`: Stops the project### Making a POST request to create a fact:
```bash
curl -X POST \
-H "Content-Type: application/json" \
-d '{"info": "Shark teeth are embedded in the gums rather than directly affixed to the jaw, and are constantly replaced throughout life.", "source": "https://en.wikipedia.org/wiki/Shark"}'\
-s http://localhost:3000/fact
```### Testing with cURL:
```bash
curl -H Accept:text/event-stream http://localhost:3000/events
```### Credits
[Digital Ocean](https://www.digitalocean.com/community/tutorials/nodejs-server-sent-events-build-realtime-app)