https://github.com/ceramicnetwork/cross-eventsource
EventSource for Node.js and a browser
https://github.com/ceramicnetwork/cross-eventsource
Last synced: 9 months ago
JSON representation
EventSource for Node.js and a browser
- Host: GitHub
- URL: https://github.com/ceramicnetwork/cross-eventsource
- Owner: ceramicnetwork
- Created: 2024-01-12T15:01:57.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-12T15:02:43.000Z (over 2 years ago)
- Last Synced: 2025-10-01T22:34:19.944Z (9 months ago)
- Language: TypeScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cross-eventsource
Provides [EventSource](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) for Node.js and browser.
If in browser, use standard `globalThis.EventSource`. If in Node.js, use EventSource implementation
of [eventsource package](https://www.npmjs.com/package/eventsource).
## Installation
```shell
pnpm add cross-eventsource
```
## Usage
```typescript
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...')
```