Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
A multi-user real-time chat app built on Val Town with persistent message history.
- Username join gate — users pick a unique username before entering chat
- Real-time messaging — Server-Sent Events (SSE) push new messages to all connected clients instantly
- Persistent history — messages are stored in SQLite and loaded on page reload
- Online user list — sidebar shows who's currently connected
- Join/leave notifications — system messages when users enter or leave
- Validation — empty usernames, empty messages, duplicate usernames, and oversized messages are all rejected with clear error messages
- Multi-tab support — open in multiple browser tabs with different usernames to test
Rendering mermaid diagram...
| Method | Path | Description |
|---|---|---|
POST | /api/join | Validate & claim a username |
GET | /api/stream?username= | SSE stream for real-time events |
GET | /api/messages | Fetch chat history (last 200) |
POST | /api/messages | Send a new message |
main.tsx— HTTP server with API routes, SSE streaming, BroadcastChannelindex.html— Join screen + chat UIscript.js— Client-side logic (SSE client, form handling)style.css— Chat layout and styling