Skip to main content

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 your wrangler.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
Usage:
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 dev

D1 Databases

Serverless SQL database built on SQLite.
wrangler.json
Usage:
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
Usage:
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
Usage:

Service Bindings

Call other Workers directly without HTTP overhead.
wrangler.json
Usage:

Queue Bindings

Send and consume messages from Cloudflare Queues.
wrangler.json
Producer:
Consumer:

Environment Variables

Simple string values for configuration.
wrangler.json
Usage:

Secrets

Secure values that are encrypted and not visible in config.
Usage:
Never commit secrets to version control. Always use wrangler secret to manage sensitive values.

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:
Resources are created with default names: {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
❌ Error: Duplicate binding name DATA

Type Safety

Define TypeScript types for your bindings:
env.d.ts

Multiple Environments

Different bindings for development, staging, and production:
wrangler.json
Deploy to specific environment:

Viewing Bindings

Print all configured bindings:
Output shows:

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.