W3C compliant EventSource client for Node.js

npm install eventsource
426 downloads in the last day
1 914 downloads in the last week
9 416 downloads in the last month

EventSource Build Status Dependencies Bitdeli Badge


This library implements the EventSource client for Node.js. The API aims to be W3C compatible.


npm install eventsource


var EventSource = require('eventsource');

var es = new EventSource('');
es.onmessage = function(e) {
es.onerror = function() {

See the spec for API docs.



Extensions to the W3C API

Setting HTTP request headers

You can define custom HTTP headers for the initial HTTP request. This can be useful for e.g. sending cookies or to specify an initial Last-Event-ID value.

HTTP headers are defined by assigning a headers attribute to the optional eventSourceInitDict argument:

var eventSourceInitDict = {headers: {'Cookie': 'test=test'}};
var es = new EventSource(url, eventSourceInitDict);

Allow unauthorized HTTPS requests

By default, https requests that cannot be authorized will cause connection to fail and an exception to be emitted. You can override this behaviour:

var eventSourceInitDict = {rejectUnauthorized: false};
var es = new EventSource(url, eventSourceInitDict);

Note that for Node.js < v0.10.x this option has no effect - unauthorized HTTPS requests are always allowed.

npm loves you