sse-fake-server
v1.0.4
Published
Server Sent Events fake server for testing your code with data.
Downloads
702
Readme
SSE-Fake-Server
Simple "Server Sent Events" fake server for testing your code with dynamic data.
Install
Install, using NPM:
$ npm install sse-fake-server
How to Use
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.
Client
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>
License
MIT. © 2017 Taras Batenkov