Listen to Server-Sent Events sincerely, most definitely


Listen to Server-Sent Events, sincerely, most definitely

Please see node-easysse for a demo

Using node-easysse with express

var require("easysse");
app.get("/chat-stream", easysse);
app.post("/chat", function(reqres) {
  easysse.emit("chat", req.body.username, req.body.message);

Using easysse-client

<script src="easysse-client.js"></script>
  var client = easysseClient.connect("/chat-stream");
  client.on("chat", function(usernamemessage){
    console.log(username, "says", message);
  $.post("/chat", {username: "mjackson", message: "hehe"});
  // "mjackson says hehe" 
  • on(eventType, cb) — add an event listener of eventType.

    (alias addEventListener)

  • off(eventType, cb) — remove an event listener of eventType.

    (alias addEventListener)

Tested on Chrome 33 Please submit any other compatibility reports

© 2014 nkitsune, mosdef.biz easysse-client may be freely distributed under the BSD license. For all details and documentation: https://github.com/mosdefbiz/easysse-client