Simple "Server Sent Events" fake server for testing your code with dynamic data.
Install, using NPM:
$ npm install sse-fake-server
Just create "fakeServer.js" file:
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:
$ node fakeServer.js
Now fake server listen on http://localhost:5555.
Simple SSE usage:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>SSE Client</title>
</head>
<body>
<script>
// 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);
});
</script>
</body>
</html>
MIT. © 2017 Taras Batenkov