workerd runtime used in production. It provides a full-featured development environment with support for all Cloudflare bindings.
Installation
Basic Usage
Constructor
new Miniflare(options)
Creates a new Miniflare instance.
MiniflareOptions
required
Configuration options
Instance Methods
dispatchFetch()
Send an HTTP request to the worker.
RequestInfo
required
URL or Request object
RequestInit
Request initialization options
Promise<Response>
HTTP response from the worker
getWorker()
Get a worker instance by name.
string
Worker name (optional for single-worker setups)
Promise<MiniflareWorker>
Worker instance with methods:
getBindings()
Get all bindings for a worker.
string
Worker name (optional for single-worker setups)
Promise<Bindings>
Object containing all worker bindings (KV, D1, R2, DO, etc.)
getCf()
Get the simulated request.cf object.
Promise<IncomingRequestCfProperties>
Simulated cf object with geolocation and other properties
getServiceURL()
Get the URL for accessing a worker.
string
Worker name
Promise<URL>
URL for accessing the worker
setOptions()
Update Miniflare options without restarting.
Partial<MiniflareOptions>
required
New options to apply
Promise<void>
Resolves when options are applied
dispose()
Stop Miniflare and clean up resources.
Promise<void>
Resolves when cleanup is complete
Binding Configuration
KV Namespaces
Record<string, string>
Map of binding names to namespace IDs
boolean | string
Enable persistence (true for default path, or specify directory)
Durable Objects
Record<string, string | DurableObjectOptions>
Map of binding names to class names or configuration objects
boolean | string
Enable persistence
R2 Buckets
Record<string, string>
Map of binding names to bucket names
boolean | string
Enable persistence
D1 Databases
Record<string, string>
Map of binding names to database IDs
boolean | string
Enable persistence
Service Bindings
Record<string, string | ServiceDesignator>
Map of binding names to service names or designators
Queue Bindings
Record<string, string>
Map of binding names to queue names
Record<string, QueueConsumerOptions>
Map of queue names to consumer options
Environment Variables
Record<string, any>
Environment variables and simple bindings
Persistence
Miniflare can persist data to disk for all storage bindings.string
Default root directory for all persisted data