express-stream-sse

    1.0.2 • Public • Published

    express-stream-sse

    npm license github-issues Circle CI build status

    Convert NodeJS streams to Server-Sent Events express routes (EventSource)

    nodei.co

    Install

    npm i -S express-stream-sse

    Usage

     
    import express from 'express';
    import streamToSSE from 'express-stream-sse';
     
    let app = express();
     
    app.get('/events', function(req, res) {
     
        var stream = require('./getSampleStream');
     
        return streamToSSE(res, stream);
     
    });
     
    app.listen(process.env.PORT || 4000);

    Then on the client side you can :

     
    var source = new EventSource('/events');
     
    source.onmessage = function(e) {
      document.body.innerHTML += e.data + '<br>';
    };
     

    Dependencies

    Package Version Dev
    babel-cli ^6.3.17
    babel-eslint *
    babel-preset-es2015 *
    babel-tape-runner *
    eslint *
    eslint-config-airbnb *
    node-interval-stream 1.0.0
    node-readme ^0.1.8
    tap-spec ^4.0.2
    tape ^4.0.0
    zuul ^3.8.0

    Author

    Julien Bouquillon julien@bouquillon.com http://github.com/revolunet

    License

    Install

    npm i express-stream-sse

    DownloadsWeekly Downloads

    4

    Version

    1.0.2

    License

    MIT

    Last publish

    Collaborators

    • avatar