Skip to main content

Overview

Watch N Chill uses environment variables to configure Redis connections, CORS settings, rate limiting, and server behavior. All variables are optional with sensible defaults for local development.

Redis Configuration

REDIS_URL
string
default:"redis://localhost:6379"
Redis connection URL for room state, chat history, and rate limiting.Local development:
REDIS_URL=redis://localhost:6379
Upstash Redis (production):
REDIS_URL=rediss://default:<password>@<your-subdomain>.upstash.io:6379
The application automatically detects Upstash URLs (containing upstash.io) and configures TLS accordingly.

Server Configuration

NODE_ENV
string
default:"development"
Node.js environment mode. Set to production for production deployments.
NODE_ENV=production
Rate limiting is only enforced when NODE_ENV=production. Development mode disables rate limiting for easier testing.
PORT
number
default:"3000"
HTTP server port for the application.
PORT=3000
HOSTNAME
string
default:"localhost (dev) | 0.0.0.0 (prod)"
Hostname the server binds to. Automatically set based on NODE_ENV.
HOSTNAME=0.0.0.0

CORS Configuration

ALLOWED_ORIGINS
string
default:"http://localhost:3000 (dev)"
Comma-separated list of allowed origins for Socket.IO CORS.Required in production to enable cross-origin Socket.IO connections.
ALLOWED_ORIGINS=https://watchnchill.app,https://www.watchnchill.app
In development mode, http://localhost:3000 is automatically allowed. In production, you must explicitly set this variable.

Rate Limiting

RATE_LIMIT_WINDOW_MS
number
default:"60000"
Time window in milliseconds for HTTP rate limiting (1 minute default).
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS
number
default:"360"
Maximum HTTP requests allowed per IP within the rate limit window.
RATE_LIMIT_MAX_REQUESTS=360
Default allows 360 requests per minute (6 requests per second).
RATE_LIMIT_SOCKET_MAX_PER_IP
number
default:"10"
Maximum concurrent Socket.IO connections allowed per IP address.
RATE_LIMIT_SOCKET_MAX_PER_IP=10

Next.js Configuration

NEXT_TELEMETRY_DISABLED
boolean
default:"false"
Disable Next.js telemetry collection.
NEXT_TELEMETRY_DISABLED=1

Complete Examples

# Redis - local instance
REDIS_URL=redis://localhost:6379

# Server configuration
NODE_ENV=development
PORT=3000

# CORS (auto-configured for localhost in dev)
# ALLOWED_ORIGINS not needed for local development

# Rate limiting (disabled in development)
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=360
RATE_LIMIT_SOCKET_MAX_PER_IP=10

Environment Variable Loading

The application loads environment variables in the following order:
  1. System environment variables
  2. .env.local (local development, gitignored)
  3. .env.production (production builds)
  4. .env (committed defaults)
Never commit .env.local or any file containing production credentials to version control.

Validation

The application validates critical environment variables at startup:
  • REDIS_URL: Automatically tested on connection. Logs errors if Redis is unavailable.
  • Rate limiting: Falls back to in-memory rate limiting if Redis connection fails.
  • CORS: Defaults to localhost in development, requires explicit configuration in production.
Check the server logs on startup to verify your configuration:
> Initializing Redis connection...
> Redis connected successfully
> Redis ready for commands
> Ready on http://0.0.0.0:3000
> Socket.IO server running on path: /api/socket/io

Build docs developers (and LLMs) love