Documentation

Bindings

ready

Declare all 18 Cloudflare Worker bindings (R2, KV, D1, Hyperdrive, Queues, Durable Objects, Workflows, Vectorize, Workers AI, Images, Services, Browser, Analytics Engine, Dispatch Namespaces, mTLS, Rate Limiters, Secrets Store, Version Metadata) in nextdeploy.yml and access them cleanly with generated TypeScript types.

Source reference: cli/internal/serverless/cloudflare/bindings.go, cli/internal/serverless/cloudflare/typegen.go, shared/config/


Declarative Bindings in nextdeploy.yml

Declare Cloudflare resources once in nextdeploy.yml. Using the binding: shorthand under resources.* automatically provisions the resource AND wires the matching Worker binding — or declare explicit bindings.* entries with ref: or IDs:

version: "1.0"
target_type: serverless

app:
  name: my-edge-app
  domain: app.example.com
  environment: production

serverless:
  provider: cloudflare
  cloudflare:
    engine: auto
    compatibility_date: "2026-05-01"
    compatibility_flags:
      - nodejs_compat
    resources:
      kv:
        - name: rate-limit-kv
          binding: RATE_LIMIT
      d1:
        - name: app-prod-db
          binding: DB
          migrations_dir: ./migrations
          protect: true
      r2:
        - name: uploads-bucket
          binding: UPLOADS
          location_hint: weur
      queues:
        - name: jobs-queue
          binding: JOBS
      hyperdrive:
        - name: pg-primary
          binding: HYPERDRIVE
          origin_env: DATABASE_URL
    bindings:
      ai:
        - name: AI
      images:
        - name: IMAGES
      services:
        - name: AUTH_SVC
          service: auth-worker
          entrypoint: AuthRPC
      analytics_engine:
        - name: METRICS
          dataset: app_metrics
      version_metadata:
        name: CF_VERSION_METADATA

Credentials are read from CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID environment variables, nextdeploy creds set --provider cloudflare, or doppler run -- — never committed to nextdeploy.yml.

Auto-Injected Bindings

  • ASSETS (R2): Automatically created and bound for your app's static assets, prerendered .html/.rsc pages, and CloudflareCacheHandler L2 storage unless you declare your own ASSETS binding (or enable static_assets.mode: workers_assets).
  • secret_text bindings: Runtime secrets from .env / Doppler / secret providers are folded automatically into the Worker upload and mirrored onto process.env. Duplicate binding names (e.g. an .env key colliding with ASSETS or DB) fail fast before upload.

Accessing Bindings with Generated TypeScript Types (nextdeploy types)

Run nextdeploy types to generate nextdeploy-env.d.ts directly from nextdeploy.yml:

nextdeploy types

Then read any binding inside Next.js Route Handlers, Server Components, or Server Actions via globalThis.__nextdeployEnv (never process.env — process.env only holds string secrets and plain-text vars):

// lib/env.ts
export function getEnv(): CloudflareEnv {
  return (globalThis.__nextdeployEnv ?? {}) as CloudflareEnv
}

// app/api/health/route.ts
import { NextResponse } from 'next/server'
import { getEnv } from '@/lib/env'

export async function GET() {
  const { DB, CF_VERSION_METADATA } = getEnv()
  const row = await DB.prepare('SELECT 1 AS ok').first()
  return NextResponse.json({ ok: row?.ok === 1, version: CF_VERSION_METADATA?.id })
}

Related