Wrangler Config
wrangler.toml configuration for Workers and Pages
Basic Structure
The wrangler.toml file configures your Cloudflare project. For Pages projects, it primarily defines bindings and compatibility settings:
# Cloudflare Pages project configuration
compatibility_date = "2024-12-01"
For standalone Workers, it also includes the entry point and routing:
name = "my-worker"
main = "src/index.ts"
compatibility_date = "2024-12-01"
Bindings
Bindings connect your code to Cloudflare services.
KV Namespaces
[[kv_namespaces]]
binding = "MY_KV"
id = "abc123def456ghi789"
D1 Databases
[[d1_databases]]
binding = "DB"
database_name = "my-database"
database_id = "abc123-def456-ghi789"
R2 Buckets
[[r2_buckets]]
binding = "FILES"
bucket_name = "my-files"
Environment Variables
[vars]
API_ENDPOINT = "https://api.example.com"
For secrets (API keys, tokens), use wrangler secret put:
npx wrangler secret put MY_SECRET
🚨 Never Put Secrets in wrangler.toml
The [vars] section is for non-sensitive configuration only. Secrets should be set via wrangler secret put or the Cloudflare dashboard. wrangler.toml is committed to git.
Pages-Specific Options
For Pages projects, you can specify the build output directory:
pages_build_output_dir = "./dist"
Multiple Bindings Example
A real-world wrangler.toml from a project using KV, D1, and R2:
# Cloudflare Pages project configuration
compatibility_date = "2024-12-01"
pages_build_output_dir = "./dist"
[vars]
AUTH0_DOMAIN = "placeholder.us.auth0.com"
AUTH0_CLIENT_ID = "placeholder"
[[d1_databases]]
binding = "DB"
database_name = "my-app"
database_id = "placeholder"
[[r2_buckets]]
binding = "FILES"
bucket_name = "my-app-files"
[[kv_namespaces]]
binding = "CACHE"
id = "placeholder"
💡 Placeholder IDs
Use placeholder values in wrangler.toml for database IDs and KV namespace IDs in source control. The actual IDs are environment-specific and should be managed per environment.