Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 720 Bytes

README.md

File metadata and controls

28 lines (21 loc) · 720 Bytes

cross-eventsource

Provides EventSource for Node.js and browser.

If in browser, use standard globalThis.EventSource. If in Node.js, use EventSource implementation of eventsource package.

Installation

pnpm add cross-eventsource

Usage

import { EventSource  } from "cross-eventsource";

// And then use it like in a browser
const source = new EventSource('http://localhost/feed')
source.addEventListener('message', (event) => {
  console.log('message', event)
})
source.addEventListener('error', error => {
  console.log('error', error)
})
console.log('listening...')