Skip to content

SSE Fake Server for testing your code with stream data

Notifications You must be signed in to change notification settings

aminqp/SSE-Fake-Server

 
 

Repository files navigation

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

About

SSE Fake Server for testing your code with stream data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%