Giter VIP home page Giter VIP logo

express-eventsource's Introduction

Server Side Events using Node, Express and EventSource

This simple demo shows streaming events from server to client, using EventSource.

  • The server (app.js) streams a list of 10 random numbers, one every 3 seconds, or until the client stops listening.
  • The client (main.js) listens to the stream, prints the results and stops listening after the last number has been received.

Install

You may need to install some missing modules with npm

Once node and npm are installed, you can checkout the source and install the missing modules:

$ git clone https://github.com/TravelingTechGuy/express-eventsource.git
$ cd ./express-eventsource
$ npm install
$ node app

Now, browse to your localhost (ie: http://localhost:3000) in your web browser.

Online demo

An online demo is available on Heroku at http://express-eventsource.herokuapp.com/ Online demo

Missing from the demo:

  • Proper error handling
  • Tests
  • Grunt project

IE Support

Since IE (at least up to version 9) does not support EventSource, I'm using this polyfill by Yaffle. I've used Modernizr to bootstrap it when needed (and found out I need to bootstrap the test into Modernizr :) ). It requires some server-side changes:

  1. The event name and the way it's added
  2. Response headers
  3. An additional 2k padding at the top of the header - apparently necessary

Ingredients

###Client side:

###Server side:

express-eventsource's People

Contributors

travelingtechguy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.