Self-Hosting
Run the Flock server on your own infrastructure with Docker Compose.
The Flock server is a single Node.js process. You can run it with npx, Docker, or embed it in an existing Node server. This guide covers the recommended Docker Compose setup for production.
Quickstart: npx
For local development or quick experiments:
The server starts on port 8787 with no Redis (in-memory only, no TTL eviction). Fine for a single dev machine.
Production: Docker Compose
For production you'll want Redis alongside the server. Redis enables presence TTL eviction (users are cleaned up when they close the tab without a clean disconnect) and horizontal scaling across multiple server instances.
Create a docker-compose.yml:
Start it:
Check it's running:
Building the image yourself
If you want to build from source rather than using the published image:
Environment variable reference
| Variable | Default | Description |
|---|---|---|
FLOCK_PORT | 8787 | Port the server listens on |
FLOCK_REDIS_URL | — | Redis URL. Omit to run without Redis (no TTL eviction, single-instance only) |
FLOCK_API_KEYS | — | Comma-separated list of accepted API keys. Omit for unauthenticated (open) mode |
FLOCK_PRESENCE_TTL_SECONDS | 30 | Seconds before an idle user (stopped heartbeating) is evicted |
FLOCK_HEARTBEAT_INTERVAL_MS | 10000 | Expected client heartbeat interval |
FLOCK_MAX_MESSAGES_PER_SECOND | 100 | Per-connection rate limit; connections above this are closed |
FLOCK_LOG_LEVEL | info | Pino log level: trace, debug, info, warn, error, silent |
API key authentication
If you set FLOCK_API_KEYS, the server rejects any client that doesn't send a matching key. Add the key to your client:
Keep the key out of version control. In Vercel or similar platforms, add it as an environment variable and reference it in your Next.js app:
Redis keyspace notifications
The --notify-keyspace-events Ex flag is required for presence TTL eviction to work. Without it, Redis won't publish expired-key events and the server won't know when a user's heartbeat has expired.
If you're using a managed Redis service (Upstash, Redis Cloud, etc.), enable keyspace notifications in the provider's dashboard. Upstash exposes this as a toggle. Redis Cloud has it in the database config.
Reverse proxy / TLS
For production, put the server behind nginx or Caddy to handle TLS termination. The server speaks plain WebSocket and HTTP; your reverse proxy upgrades ws:// to wss:// for the client.
Minimal nginx snippet for a WebSocket upstream:
Next steps
- Scaling guide — how to run multiple instances behind a load balancer
- Configuration reference — full env var docs