Skip to main content
Bindings give workers access to external resources and configuration settings. For ES modules syntax, bindings are delivered via the env object. For service worker syntax, bindings appear as global variables.

Structure

name
Text
required
Name of the binding. Becomes the property name in env (ES modules) or the global variable name (service workers).

Binding types

Simple values

text
Text
A string value.
data
Data
An ArrayBuffer.
json
Text
A value parsed from JSON.

Service bindings

service
ServiceDesignator
Binding to a named service (possibly another worker).
bindings = [
  (name = "BACKEND", service = "my-service")
]

Durable Objects

durableObjectNamespace
DurableObjectNamespaceDesignator
Binding to a Durable Object namespace.In the common case where this refers to a class in the same worker, you can specify just a string:
bindings = [
  (name = "COUNTER", durableObjectNamespace = "Counter")
]
  • className: Exported class name implementing the Durable Object
  • serviceName: Service name defining the class (optional, defaults to current worker)
durableObjectClass
ServiceDesignator
A Durable Object class binding without an actual storage namespace. Used to implement facets.

Storage services

kvNamespace
ServiceDesignator
A KV namespace. Operations are converted to HTTP requests to the named service.
r2Bucket
ServiceDesignator
An R2 bucket binding. Operations are converted to HTTP requests.
r2Admin
ServiceDesignator
An R2 admin API binding.

Queues and events

queue
ServiceDesignator
A Queue binding. Operations are converted to HTTP requests to the named service.
analyticsEngine
ServiceDesignator
Analytics Engine binding. Allows workers to store information through Analytics Engine Events.Requires --experimental flag.

Database connections

hyperdrive
group
Hyperdrive binding for Postgres database caching and pooling.
  • designator: ServiceDesignator
  • database: Database name
  • user: Username
  • password: Password
  • scheme: Connection scheme

WebAssembly and crypto

wasmModule
Data
A WebAssembly module. The binding is a WebAssembly.Module instance. Only supported in service worker syntax.Deprecated: Use ES modules syntax with WASM modules instead.
cryptoKey
CryptoKey
A CryptoKey instance for use with the WebCrypto API.By setting extractable = false, you prevent the worker from accessing raw key material; the key can only be used in WebCrypto operations.Fields:
  • raw, hex, base64: Raw key material (for symmetric keys)
  • pkcs8: Private key in PEM-encoded PKCS#8 format
  • spki: Public key in PEM-encoded SPKI format
  • jwk: Key in JSON format
  • algorithm: Algorithm name or JSON object
  • extractable: Allow worker to export key material (default: false)
  • usages: List of permitted operations (encrypt, decrypt, sign, verify, deriveKey, deriveBits, wrapKey, unwrapKey)

Advanced bindings

wrapped
WrappedBinding
Wraps a collection of inner bindings with common API functionality.
  • moduleName: Internal wrapper module name
  • entrypoint: Function name to call (default: “default”)
  • innerBindings: List of bindings passed to wrapper function
fromEnvironment
Text
Takes the value from a system environment variable. The binding value is null if the environment variable is not set.
unsafeEval
Void
Enables access to the UnsafeEval API.
memoryCache
group
In-memory cache binding. Multiple isolates can access the same cache within the same process.
  • id: Cache identifier
  • limits: MemoryCacheLimits
    • maxKeys: Maximum number of keys
    • maxValueSize: Maximum size of a single value
    • maxTotalValueSize: Maximum total size of all values
workerLoader
group
Dynamically load workers from code at runtime. Acts as a cache, automatically unloading unused workers.
  • id: Optional identifier for sharing across multiple bindings
workerdDebugPort
Void
Provides a connect() method to dynamically connect to any workerd instance’s debug port via WorkerdDebugPort RPC interface.For local development and testing only.

Parameter bindings

parameter
group
Indicates the worker requires a binding of the given type, but it won’t be specified here. Another worker can inherit this worker and fill in the binding.
  • type: Expected type of this parameter
  • optional: If true, derived workers need not specify it (default: false)

Example

bindings = [
  ( name = "API_KEY",
    text = "secret-key-value"
  ),
  ( name = "CONFIG",
    json = "{\"timeout\": 30}"
  ),
  ( name = "BACKEND",
    service = "backend-service"
  ),
  ( name = "COUNTER",
    durableObjectNamespace = "Counter"
  ),
  ( name = "KV",
    kvNamespace = "kv-service"
  ),
  ( name = "SECRET_KEY",
    cryptoKey = (
      raw = embed "secret.key",
      algorithm = (name = "AES-GCM"),
      extractable = false,
      usages = ["encrypt", "decrypt"]
    )
  )
]

Build docs developers (and LLMs) love