Gathering detailed insights and metrics for eventsource
Gathering detailed insights and metrics for eventsource
Gathering detailed insights and metrics for eventsource
Gathering detailed insights and metrics for eventsource
eventsource-parser
Streaming, source-agnostic EventSource/Server-Sent Events parser
eventsource-polyfill
A browser polyfill for W3C EventSource (http://www.w3.org/TR/eventsource/)
faye-websocket
Standards-compliant WebSocket server and client
@types/eventsource
Stub TypeScript definitions entry for eventsource, which provides its own types definitions
EventSource client for Node.js, browsers and other JavaScript runtimes
npm install eventsource
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.5
Supply Chain
100
Quality
87.7
Maintenance
100
Vulnerability
100
License
TypeScript (99.04%)
HTML (0.96%)
Total Downloads
2,312,051,525
Last Day
515,644
Last Week
7,947,475
Last Month
40,654,095
Last Year
258,133,465
MIT License
1,042 Stars
391 Commits
260 Forks
32 Watchers
7 Branches
46 Contributors
Updated on Jun 30, 2025
Minified
Minified + Gzipped
Latest Version
4.0.0
Package Id
eventsource@4.0.0
Unpacked Size
143.21 kB
Size
23.79 kB
File Count
13
NPM Version
10.9.2
Node Version
22.15.0
Published on
May 13, 2025
Cumulative downloads
Total Downloads
Last Day
-1.4%
515,644
Compared to previous day
Last Week
-11%
7,947,475
Compared to previous week
Last Month
71.2%
40,654,095
Compared to previous month
Last Year
2.6%
258,133,465
Compared to previous year
1
20
WhatWG/W3C-compatible server-sent events/eventsource client. The module attempts to implement an absolute minimal amount of features/changes beyond the specification.
If you're looking for a modern alternative with a less constrained API, check out the eventsource-client
package.
1npm install --save eventsource
Basically, any environment that supports:
If you need to support older runtimes, try the 2.x
branch/version range (note: 2.x branch is primarily targetted at Node.js, not browsers).
1import {EventSource} from 'eventsource' 2 3const es = new EventSource('https://my-server.com/sse') 4 5/* 6 * This will listen for events with the field `event: notice`. 7 */ 8es.addEventListener('notice', (event) => { 9 console.log(event.data) 10}) 11 12/* 13 * This will listen for events with the field `event: update`. 14 */ 15es.addEventListener('update', (event) => { 16 console.log(event.data) 17}) 18 19/* 20 * The event "message" is a special case, as it will capture events _without_ an 21 * event field, as well as events that have the specific type `event: message`. 22 * It will not trigger on any other event type. 23 */ 24es.addEventListener('message', (event) => { 25 console.log(event.data) 26}) 27 28/** 29 * To explicitly close the connection, call the `close` method. 30 * This will prevent any reconnection from happening. 31 */ 32setTimeout(() => { 33 es.close() 34}, 10_000)
Make sure you have configured your TSConfig so it matches the environment you are targetting. If you are targetting browsers, this would be dom
:
1{ 2 "compilerOptions": { 3 "lib": ["dom"], 4 }, 5}
If you're using Node.js, ensure you have @types/node
installed (and it is version 18 or higher). Cloudflare workers have @cloudflare/workers-types
etc.
The following errors are caused by targetting an environment that does not have the necessary types available:
error TS2304: Cannot find name 'Event'.
error TS2304: Cannot find name 'EventTarget'.
error TS2304: Cannot find name 'MessageEvent'.
See MIGRATION.md for a detailed migration guide.
The error
event has a message
and code
property that can be used to get more information about the error. In the specification, the Event
1es.addEventListener('error', (err) => { 2 if (err.code === 401 || err.code === 403) { 3 console.log('not authorized') 4 } 5})
fetch
implementationThe EventSource
constructor accepts an optional fetch
property in the second argument that can be used to specify the fetch
implementation to use.
This can be useful in environments where the global fetch
function is not available - but it can also be used to alter the request/response behaviour.
1const es = new EventSource('https://my-server.com/sse', {
2 fetch: (input, init) =>
3 fetch(input, {
4 ...init,
5 headers: {
6 ...init.headers,
7 Authorization: 'Bearer myToken',
8 },
9 }),
10})
Use a package like node-fetch-native
to add proxy support, either through environment variables or explicit configuration.
1// npm install node-fetch-native --save 2import {fetch} from 'node-fetch-native/proxy' 3 4const es = new EventSource('https://my-server.com/sse', { 5 fetch: (input, init) => fetch(input, init), 6})
Use a package like undici
for more control of fetch options through the use of an Agent
.
1// npm install undici --save 2import {fetch, Agent} from 'undici' 3 4await fetch('https://my-server.com/sse', { 5 dispatcher: new Agent({ 6 connect: { 7 rejectUnauthorized: false, 8 }, 9 }), 10})
MIT-licensed. See LICENSE.
9.3/10
Summary
Exposure of Sensitive Information in eventsource
Affected Versions
>= 2.0.0, < 2.0.2
Patched Versions
2.0.2
9.3/10
Summary
Exposure of Sensitive Information in eventsource
Affected Versions
< 1.1.1
Patched Versions
1.1.1
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
9 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 8
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More