This guide walks you through creating a minimal real-time WebSocket server that broadcasts every incoming message to all connected clients. By the end you will have a running Worker on Cloudflare with a browser client that connects to it viaDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/cloudflare/partykit/llms.txt
Use this file to discover all available pages before exploring further.
PartySocket.
Install the packages
Create a new Workers project and install
partyserver for the server side and partysocket for the browser client.Write the Server class
Replace the contents of Key points:
src/index.ts with the following. The Server class you export is a Durable Object subclass — PartyKit wires up the WebSocket plumbing so you only implement the hooks you care about.this.name— the room name resolved from the URL, available in every hook.this.broadcast(message, [connection.id])— sendsmessageto all clients, excluding the sender.routePartykitRequest— matches incoming requests to your Durable Object bindings automatically; returnsnullfor non-matching paths so your fallbackResponsehandles them.
Configure wrangler.jsonc
Open
wrangler.jsonc and add durable_objects bindings and a migration entry. The binding name must match the exported class name exactly (case-insensitive match is done by routePartykitRequest after kebab-casing).Connect from the browser with PartySocket
Create a client-side file (or add to an existing frontend build) that uses
PartySocket to connect. PartySocket automatically constructs the /parties/:party/:room URL that routePartykitRequest expects, and handles reconnections transparently.party is the kebab-cased version of your Durable Object binding name. MyServer becomes my-server, ChatRoom becomes chat-room, and so on. routePartykitRequest performs this conversion automatically on the server side.Deploy with Wrangler
Run the Wrangler deploy command from your project root. Wrangler bundles your Worker, applies the Durable Object migration, and publishes everything to Cloudflare’s edge.You should see output similar to:To run locally during development, use:Wrangler’s local dev environment simulates Durable Objects in-process, so you can iterate quickly before deploying. Your
PartySocket client can point to localhost:8787 during development.What’s next?
- Enable hibernation to reduce costs when rooms are idle.
- Use
getConnectionTagsandgetConnections(tag)to filter broadcasts to subsets of clients. - Add
onRequestto handle HTTP requests inside the same Durable Object. - Explore
y-partyserverfor real-time collaborative text editing with Yjs.