Overview
Bindings allow your Worker to interact with Cloudflare resources like KV namespaces, D1 databases, R2 buckets, Durable Objects, and other services. Bindings are configured in yourwrangler.json and made available to your Worker at runtime.
Bindings are environment variables that provide access to resources. They’re type-safe in TypeScript and validated at deployment time.
Binding Types
KV Namespaces
Key-value storage for reading and writing data globally.wrangler.json
string
required
Variable name to access the namespace in your code
string
required
KV namespace ID (obtained from dashboard or CLI)
string
Different namespace to use during local development with
wrangler devD1 Databases
Serverless SQL database built on SQLite.wrangler.json
string
required
Variable name to access the database
string
D1 database UUID (required for deployment, can be omitted if
database_name exists)string
Database name for reference and auto-provisioning
R2 Buckets
Object storage compatible with S3 API.wrangler.json
string
required
Variable name to access the bucket
string
required
R2 bucket name (must be unique per account)
string
Data jurisdiction for compliance (e.g.,
"eu" for GDPR)Durable Objects
Stateful objects with persistent storage and guaranteed single-instance execution.wrangler.json
Service Bindings
Call other Workers directly without HTTP overhead.wrangler.json
Queue Bindings
Send and consume messages from Cloudflare Queues.wrangler.json
Environment Variables
Simple string values for configuration.wrangler.json
Secrets
Secure values that are encrypted and not visible in config.Auto-Provisioning
Wrangler can automatically create resources during deployment if they don’t exist.Interactive Provisioning
During deployment, Wrangler prompts to create missing resources:Auto-Create Mode
Use--auto-create to skip prompts:
{worker-name}-{binding-name}
Resource Inheritance
If a Worker is already deployed with bindings, Wrangler can inherit them:wrangler.json
Inherited bindings use the same resource from the previous deployment. This is useful when restructuring config without changing resource IDs.
Binding Validation
Wrangler validates bindings at deployment time:Name Conflicts
wrangler.json
DATA
Type Safety
Define TypeScript types for your bindings:env.d.ts
Multiple Environments
Different bindings for development, staging, and production:wrangler.json
Viewing Bindings
Print all configured bindings:Best Practices
Use Descriptive Names
Name bindings clearly:
USER_KV, PRODUCT_DB, UPLOAD_BUCKET rather than generic names.Separate Environments
Use different resources for dev/staging/production to avoid data conflicts.
Type Your Env
Always define TypeScript interfaces for your environment to catch errors early.
Document Bindings
Add comments in config explaining what each binding is used for.