Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/enkot/sse-fake-server
SSE Fake Server for testing your code with stream data
https://github.com/enkot/sse-fake-server
fake server server-sent-events sse
Last synced: about 2 hours ago
JSON representation
SSE Fake Server for testing your code with stream data
- Host: GitHub
- URL: https://github.com/enkot/sse-fake-server
- Owner: enkot
- Created: 2017-12-02T13:07:50.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-03-06T09:12:43.000Z (9 months ago)
- Last Synced: 2024-11-17T16:16:47.712Z (2 days ago)
- Topics: fake, server, server-sent-events, sse
- Language: JavaScript
- Homepage:
- Size: 40 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SSE-Fake-Server
Simple ["Server Sent Events"](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) fake server for testing your code with dynamic data.## Install
Install, using NPM:
```sh
$ npm install sse-fake-server
```## How to Use
### Server
Just create "fakeServer.js" file:
```javascript
const SSEServer = require('sse-fake-server');// Pass callback to SSEServer
SSEServer(client => {
// Every 2 seconds send data to client
setInterval(() => {
client.send('Stream Hello!')
}, 2000);
});
```
Run it:
```sh
$ node fakeServer.js
```
Now fake server listen on http://localhost:5555/stream.
### Client
Simple SSE usage:
```html
SSE Client
// Create SSE object
var es = new EventSource("http://localhost:5555/stream");// Listen for message events from server
es.addEventListener('message', function(event) {
console.log(event.data);
});
```
## License
MIT. © 2017 Taras Batenkov