A simple demonstration of real-time updates using MongoDB Change Streams, Server-Sent Events (SSE), and HTMX. Built with the Hono web framework for Deno. Watch as items update instantly across multiple browser windows without writing any JavaScript.
- 🦕 Built with Deno and TypeScript
- 🚀 Hono web framework
- 📊 MongoDB Change Streams for real-time data
- 🔄 Server-Sent Events (SSE) for pushing updates
- ⚡ HTMX for dynamic UI updates
- 🔍 Configurable pagination limit (
ppquery parameter)
-
Install Dependencies
-
Start MongoDB with Replication
MongoDB Change Streams require a replica set. Either:
a) Add to your mongod.cfg:
replication: replSet: "rs0"
b) Or start mongod with the --replSet flag:
mongod --replSet rs0
Then initialize the replica set:
mongosh > rs.initiate()
-
Run the Application
deno task dev
-
Visit the App
http://localhost:8000
- Hono handles HTTP routing and SSE streaming
- MongoDB Change Streams watch for database updates
- Server pushes changes via SSE to connected clients
- HTMX updates the DOM without page refresh
- Items list shows most recent items first, limited by
ppparameter (default: 10)
GET /- Main page (Hono static file serving)POST /create- Create new itemGET /items?pp={limit}- List items with optional pagination limitGET /sse- SSE connection for real-time updates
├── main.ts # Hono server implementation
├── index.html # Frontend with HTMX
├── deno.json # Deno configuration
└── README.md # Documentation
- Deno - Modern runtime for JavaScript and TypeScript
- Hono - Ultrafast web framework
- MongoDB - Document database with Change Streams
- HTMX - HTML-based interactivity
MIT