cross-eventsource
v1.0.0
Published
EventSource for Node.js and Browser
Downloads
2,749
Readme
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...')