https://github.com/frameable/pollable
Long-polling with Express
https://github.com/frameable/pollable
Last synced: 10 months ago
JSON representation
Long-polling with Express
- Host: GitHub
- URL: https://github.com/frameable/pollable
- Owner: frameable
- Created: 2022-09-06T12:09:54.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-09-06T12:14:42.000Z (almost 4 years ago)
- Last Synced: 2025-06-21T13:43:27.773Z (12 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pollable
Helper class for long-polling with Express
```javascript
// server.js
app.get('/poll', (req, res) => {
const { latestMessageId } = req.query;
pollable.subscribe({ key, latestMessageId, res });
});
setInterval(_ => {
pollable.publish('channel-1', { value: Math.random() })
}, 1000);
```
```javascript
// client.js
const subscription = pollable('http://localhost:3000/poll/channel-1');
subscription.addEventListener('message', e => {
console.log("DATA", e.detail);
});
```