Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

event-source-emitter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-source-emitter

server-side EventSource

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

event-source-emitter

Server-side events with EventSource.

Example

var http        = require('http')
  , eventSource = require('event-source-emitter')
http.createServer(function(req, res) {
  var es    = eventSource(req, res, {keepAlive: true})
    , times = 0
  var interval = setInterval(function() {
    es.emit("update", {time: Date.now()})
    if (times++ > 10) {
      es.end()
      clearInterval(interval)
    }
  }, 1000)
}).listen(8765)
$ curl -v 127.0.0.1:8765

To connect to the EventSource server, use the browser's EventSource interface.

API

EventSource(req, res, {keepAlive, onClose})

  • keepAlive - Boolean, default: false. If true, send a comment every 15 seconds to guard against timeouts.
  • onClose - Function, called when the connection is terminated.

EventSource.emit(event, data)

Send an event down the event stream.

EventSource.end()

Close the connection.

EventSource.comment(text)

Send a message down the event stream. It will be ignored by the receiver.

Keywords

FAQs

Package last updated on 24 Feb 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc