🔥 Miniflare
Miniflare is a simulator for developing and testing
Cloudflare Workers, powered by
workerd.
:warning: Miniflare is a lower level API designed for tools creators, for locally developing Workers use tools built on top of Miniflare such as Wrangler or the Cloudflare Vite plugin.
Quick Start
$ npm install miniflare --save-devimport { Miniflare } from "miniflare";
// Create a new Miniflare instance, starting a workerd server
const mf = new Miniflare({
script: `addEventListener("fetch", (event) => {
event.respondWith(new Response("Hello Miniflare!"));
})`,
});
// Send a request to the workerd server, the host is ignored
const response = await mf.dispatchFetch("http://localhost:8787/");
console.log(await response.text()); // Hello Miniflare!
// Cleanup Miniflare, shutting down the workerd server
await mf.dispose();API
type Awaitable<T>
T | Promise<T>
Represents a value that can be awaited. Used in callback types to allow
Promises to be returned if necessary.
type Json
string | number | boolean | null | Record<string, Json> | Json[]
Represents a JSON-serialisable value.
type ModuleRuleType
"ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm"
Represents how a module's contents should be interpreted.
"ESModule": interpret as ECMAScript module"CommonJS": interpret as CommonJS module"Text": interpret as UTF8-encoded data, expose in runtime withstring-typeddefaultexport"Data": interpret as arbitrary binary data, expose in runtime withArrayBuffer-typeddefaultexport"CompiledWasm": interpret as binary WebAssembly module data, expose in runtime withWebAssembly.Module-typeddefaultexport
interface ModuleDefinition
Represents a manually defined module.
type: ModuleRuleTypeHow this module's contents should be interpreted.
path: stringPath of this module. The module's "name" will be obtained by converting this to a relative path. The original path will be used to read
contentsif it's omitted.contents?: string | Uint8ArrayContents override for this module. Binary data should be passed as
Uint8Arrays. If omitted, will be read frompath.
interface ModuleRule
Represents a rule for identifying the ModuleRuleType of automatically located
modules.
type: ModuleRuleTypeHow to interpret modules that match the
includepatterns.include: string[]Glob patterns to match located module paths against (e.g.
["**/*.txt"]).fallthrough?: booleanIf
true, ignore any further rules of thistype. This is useful for disabling the built-inESModuleandCommonJSrules that match*.mjsand*.js/*.cjsfiles respectively.
type Persistence
boolean | string | undefined
Represents where data should be persisted, if anywhere.
- If this is
undefined, it defaults totrueifdefaultPersistRootis set or otherwise defaults tofalse. - If this is
false, data will be stored in-memory and only persist betweenMiniflare#setOptions()calls, not restarts nornew Miniflareinstances. - If this is
true, data will be stored in a subdirectory of thedefaultPersistRootpath ifdefaultPersistRootis set or otherwise will be stored in a subdirectory of$PWD/.mf. - If this looks like a URL, then:
- If the protocol is
memory:, data will be stored in-memory as above. - If the protocol is
file:, data will be stored on the file-system, in the specified directory (e.g.file:///path/to/directory).
- If the protocol is
- Otherwise, if this is just a regular
string, data will be stored on the file-system, using the value as the directory path.
enum LogLevel
NONE, ERROR, WARN, INFO, DEBUG, VERBOSE
Controls which messages Miniflare logs. All messages at or below the selected level will be logged.
interface LogOptions
prefix?: stringString to add before the level prefix when logging messages. Defaults to
mf.suffix?: stringString to add after the level prefix when logging messages.
class Log
constructor(level?: LogLevel, opts?: LogOptions)Creates a new logger that logs all messages at or below the specified level to the
console.error(message: Error)Logs a message at the
ERRORlevel. If the constructed loglevelis less thanERROR,throws themessageinstead.warn(message: string)Logs a message at the
WARNlevel.info(message: string)Logs a message at the
INFOlevel.debug(message: string)Logs a message at the
DEBUGlevel.verbose(message: string)Logs a message at the
VERBOSElevel.
class NoOpLog extends Log
constructor()Creates a new logger that logs nothing to the
console, and alwaysthrowsmessages logged at theERRORlevel.
interface QueueProducerOptions
queueName: stringThe name of the queue where messages will be sent by the producer.
deliveryDelay?: numberDefault number of seconds to delay the delivery of messages to consumers. Value between
0(no delay) and42300(12 hours).
interface QueueConsumerOptions
maxBatchSize?: numberMaximum number of messages allowed in each batch. Defaults to
5.maxBatchTimeout?: numberMaximum number of seconds to wait for a full batch. If a message is sent, and this timeout elapses, a partial batch will be dispatched. Defaults to
1.maxRetries?: numberMaximum number of times to retry dispatching a message, if handling it throws, or it is explicitly retried. Defaults to
2.deadLetterQueue?: stringName of another Queue to send a message on if it fails processing after
maxRetries. If this isn't specified, failed messages will be discarded.retryDelay?: numberNumber of seconds to delay the (re-)delivery of messages by default. Value between
0(no delay) and42300(12 hours).
interface WorkerOptions
Options for an individual Worker/"nanoservice". All bindings are accessible on
the global scope in service-worker format Workers, or via the 2nd env
parameter in module format Workers.
interface WorkflowOptions
name: stringThe name of the Workflow.
className: stringThe name of the class exported from the Worker that implements the
WorkflowEntrypoint.scriptName?: stringThe name of the script that includes the
WorkflowEntrypoint. This is optional because it defaults to the current script if not set.
Core
name?: stringUnique name for this worker. Only required if multiple
workersare specified.rootPath?: stringPath against which all other path options for this Worker are resolved relative to. This path is itself resolved relative to the
rootPathfromSharedOptionsif multiple workers are specified. Defaults to the current working directory.script?: stringJavaScript code for this worker. If this is a service worker format Worker, it must not have any imports. If this is a modules format Worker, it must not have any npm imports, and
modules: truemust be set. If it does have imports,scriptPathmust also be set so Miniflare knows where to resolve them relative to.scriptPath?: stringPath of JavaScript entrypoint. If this is a service worker format Worker, it must not have any imports. If this is a modules format Worker, it must not have any npm imports, and
modules: truemust be set.modules?: boolean | ModuleDefinition[]If
true, Miniflare will treatscript/scriptPathas an ES Module and automatically locate transitive module dependencies according tomodulesRules. Note that automatic location is not perfect: if the specifier to a dynamicimport()orrequire()is not a string literal, an exception will be thrown.If set to an array, modules can be defined manually. Transitive dependencies must also be defined. Note the first module must be the entrypoint and have type
"ESModule".
modulesRoot?: stringIf
modulesis set totrueor an array, modules' "name"s will be theirpaths relative to this value. This ensures file paths in stack traces are correct.
modulesRules?: ModuleRule[]Rules for identifying the
ModuleRuleTypeof automatically located modules whenmodules: trueis set. Note the following default rules are always included at the end:[ { type: "ESModule", include: ["**/*.mjs"] }, { type: "CommonJS", include: ["**/*.js", "**/*.cjs"] }, ]If
scriptandscriptPathare set, andmodulesis set to an array,modulestakes priority for a Worker's code, followed byscript, thenscriptPath.
compatibilityDate?: stringCompatibility date to use for this Worker. Defaults to a date far in the past.
compatibilityFlags?: string[]Compatibility flags to use for this Worker.
bindings?: Record<string, Json>Record mapping binding name to arbitrary JSON-serialisable values to inject as bindings into this Worker.
wasmBindings?: Record<string, string>Record mapping binding name to paths containing binary WebAssembly module data to inject as
WebAssembly.Modulebindings into this Worker.textBlobBindings?: Record<string, string>Record mapping binding name to paths containing UTF8-encoded data to inject as
stringbindings into this Worker.dataBlobBindings?: Record<string, string>Record mapping binding name to paths containing arbitrary binary data to inject as
ArrayBufferbindings into this Worker.serviceBindings?: Record<string, string | typeof kCurrentWorker | { name: string | typeof kCurrentWorker, entrypoint?: string } | { network: Network } | { external: ExternalServer } | { disk: DiskDirectory } | { node: (req: http.IncomingMessage, res: http.ServerResponse, miniflare: Miniflare) => Awaitable<void> } | (request: Request, miniflare: Miniflare) => Awaitable<Response>>Record mapping binding name to service designators to inject as
{ fetch: typeof fetch }service bindings into this Worker.- If the designator is a
string, requests will be dispatched to the Worker with thatname. - If the designator is
(await import("miniflare")).kCurrentWorker, requests will be dispatched to the Worker defining the binding. - If the designator is an object of the form
{ name: ..., entrypoint: ... }, requests will be dispatched to the entrypoint namedentrypointin the Worker namedname. Theentrypointdefaults todefault, meaning{ name: "a" }is the same as"a". Ifnameis(await import("miniflare")).kCurrentWorker, requests will be dispatched to the Worker defining the binding. - If the designator is an object of the form
{ network: { ... } }, wherenetworkis aworkerdNetworkstruct, requests will be dispatched according to thefetched URL. - If the designator is an object of the form
{ external: { ... } }whereexternalis aworkerdExternalServerstruct, requests will be dispatched to the specified remote server. - If the designator is an object of the form
{ disk: { ... } }wherediskis aworkerdDiskDirectorystruct, requests will be dispatched to an HTTP service backed by an on-disk directory. - If the designator is an object of the form
{ node: (req: http.IncomingMessage, res: http.ServerResponse, miniflare: Miniflare) => Awaitable<void> }, requests will be dispatched to your custom Node handler. This allows you to access data and functions defined in Node.js from your Worker using Node.jsreqandresobjects. Note,miniflarewill be theMiniflareinstance dispatching the request. - If the designator is a function with the signature
(request: Request, miniflare: Miniflare) => Response, requests will be dispatched to your custom fetch handler. This allows you to access data and functions defined in Node.js from your Worker using fetchRequestandResponseobjects. Note,miniflarewill be theMiniflareinstance dispatching the request.
- If the designator is a
wrappedBindings?: Record<string, string | { scriptName: string, entrypoint?: string, bindings?: Record<string, Json> }>Record mapping binding name to designators to inject as wrapped bindings into this Worker. Wrapped bindings allow custom bindings to be written as JavaScript functions accepting an
envparameter of "inner bindings" and returning the value to bind. Astringdesignator is equivalent to{ scriptName: <string> }.scriptName's bindings will be used as "inner bindings". JSONbindingsin thedesignatoralso become "inner bindings" and will override any ofscriptNamebindings with the same name. The Worker namedscriptName...- Must define a single
ESModuleas its source, using{ modules: true, script: "..." },{ modules: true, scriptPath: "..." }, or{ modules: [...] } - Must provide the function to use for the wrapped binding as an
entrypointnamed export or a default export ifentrypointis omitted - Must not be the first/entrypoint worker
- Must not be bound to with service or Durable Object bindings
- Must not define
compatibilityDateorcompatibilityFlags - Must not define
outboundService - Must not directly or indirectly have a wrapped binding to itself
- Must not be used as an argument to
Miniflare#getWorker()
<summary>Wrapped Bindings Example</summary>import { Miniflare } from "miniflare"; const store = new Map<string, string>(); const mf = new Miniflare({ workers: [ { wrappedBindings: { MINI_KV: { scriptName: "mini-kv", // Use Worker named `mini-kv` for implementation bindings: { NAMESPACE: "ns" }, // Override `NAMESPACE` inner binding }, }, modules: true, script: `export default { async fetch(request, env, ctx) { // Example usage of wrapped binding await env.MINI_KV.set("key", "value"); return new Response(await env.MINI_KV.get("key")); } }`, }, { name: "mini-kv", serviceBindings: { // Function-valued service binding for accessing Node.js state async STORE(request) { const { pathname } = new URL(request.url); const key = pathname.substring(1); if (request.method === "GET") { const value = store.get(key); const status = value === undefined ? 404 : 200; return new Response(value ?? null, { status }); } else if (request.method === "PUT") { const value = await request.text(); store.set(key, value); return new Response(null, { status: 204 }); } else if (request.method === "DELETE") { store.delete(key); return new Response(null, { status: 204 }); } else { return new Response(null, { status: 405 }); } }, }, modules: true, script: ` // Implementation of binding class MiniKV { constructor(env) { this.STORE = env.STORE; this.baseURL = "http://x/" + (env.NAMESPACE ?? "") + ":"; } async get(key) { const res = await this.STORE.fetch(this.baseURL + key); return res.status === 404 ? null : await res.text(); } async set(key, body) { await this.STORE.fetch(this.baseURL + key, { method: "PUT", body }); } async delete(key) { await this.STORE.fetch(this.baseURL + key, { method: "DELETE" }); } } // env has the type { STORE: Fetcher, NAMESPACE?: string } export default function (env) { return new MiniKV(env); } `, }, ], });:warning:
wrappedBindingsare only supported in modules format Workers.- Must define a single
outboundService?: string | { network: Network } | { external: ExternalServer } | { disk: DiskDirectory } | { node: (req: http.IncomingMessage, res: http.ServerResponse, miniflare: Miniflare) => Awaitable<void> } | (request: Request, miniflare: Miniflare) => Awaitable<Response>Dispatch this Worker's global
fetch()andconnect()requests to the configured service. Service designators follow the same rules above forserviceBindings.fetchMock?: import("undici").MockAgentAn
undiciMockAgentto dispatch this Worker's globalfetch()requests through.:warning:
outboundServiceandfetchMockare mutually exclusive options. At most one of them may be specified per Worker.routes?: string[]Array of route patterns for this Worker. These follow the same routing rules as deployed Workers. If no routes match, Miniflare will fallback to the Worker defined first.
defaultPersistRoot?: stringSpecifies the default directory where Miniflare will write persisted data when persistence is enabled.
// Without `defaultPersistRoot` new Miniflare({ kvPersist: undefined, // → "/(tmp)/kv" d1Persist: true, // → "$PWD/.mf/d1" r2Persist: false, // → "/(tmp)/r2" cachePersist: "/my-cache", // → "/my-cache" }); // With `defaultPersistRoot` new Miniflare({ defaultPersistRoot: "/storage", kvPersist: undefined, // → "/storage/kv" d1Persist: true, // → "/storage/d1" r2Persist: false, // → "/(tmp)/r2" cachePersist: "/my-cache", // → "/my-cache" });
Cache
cache?: booleanIf
false, default and named caches will be disabled. The Cache API will still be available, it just won't cache anything.cacheWarnUsage?: booleanIf
true, the first use of the Cache API will log a warning stating that the Cache API is unsupported onworkers.devsubdomains.
Durable Objects
durableObjects?: Record<string, string | { className: string, scriptName?: string }>Record mapping binding name to Durable Object class designators to inject as
DurableObjectNamespacebindings into this Worker.- If the designator is a
string, it should be the name of aclassexported by this Worker. - If the designator is an object, and
scriptNameisundefined,classNameshould be the name of aclassexported by this Worker. - Otherwise,
classNameshould be the name of aclassexported by the Worker with anameofscriptName.
- If the designator is a
KV
kvNamespaces?: Record<string, string> | string[]Record mapping binding name to KV namespace IDs to inject as
KVNamespacebindings into this Worker. Different Workers may bind to the same namespace ID with different binding names. If astring[]of binding names is specified, the binding name and KV namespace ID are assumed to be the same.sitePath?: stringPath to serve Workers Sites files from. If set,
__STATIC_CONTENTand__STATIC_CONTENT_MANIFESTbindings will be injected into this Worker. In modules mode,__STATIC_CONTENT_MANIFESTwill also be exposed as a module with astring-typeddefaultexport, containing the JSON-stringified manifest. Note Workers Sites files are never cached in Miniflare.siteInclude?: string[]If set, only files with paths matching these glob patterns will be served.
siteExclude?: string[]If set, only files with paths not matching these glob patterns will be served.
assetsPath?: string
Path to serve Workers assets from.
assetsKVBindingName?: stringName of the binding to the KV namespace that the assets are in. IfassetsPathis set, this binding will be injected into this Worker.assetsManifestBindingName?: stringName of the binding to anArrayBuffercontaining the binary-encoded assets manifest. IfassetsPathis set, this binding will be injected into this Worker.
R2
r2Buckets?: Record<string, string> | string[]Record mapping binding name to R2 bucket names to inject as
R2Bucketbindings into this Worker. Different Workers may bind to the same bucket name with different binding names. If astring[]of binding names is specified, the binding name and bucket name are assumed to be the same.
D1
d1Databases?: Record<string, string> | string[]Record mapping binding name to D1 database IDs to inject as
D1Databasebindings into this Worker. Note binding names starting with__D1_BETA__are injected asFetcherbindings instead, and must be wrapped with a facade to provide the expectedD1DatabaseAPI. Different Workers may bind to the same database ID with different binding names. If astring[]of binding names is specified, the binding name and database ID are assumed to be the same.
Queues
queueProducers?: Record<string, QueueProducerOptions> | string[]Record mapping binding name to queue options to inject as
WorkerQueuebindings into this Worker. Different Workers may bind to the same queue name with different binding names. If astring[]of binding names is specified, the binding name and queue name (part of the queue options) are assumed to be the same.queueConsumers?: Record<string, QueueConsumerOptions> | string[]Record mapping queue name to consumer options. Messages enqueued on the corresponding queues will be dispatched to this Worker. Note each queue can have at most one consumer. If a
string[]of queue names is specified, default consumer options will be used.
Assets
directory?: stringPath to serve Workers static asset files from.binding?: stringBinding name to inject as aFetcherbinding to allow access to static assets from within the Worker.assetOptions?: { html_handling?: HTMLHandlingOptions, not_found_handling?: NotFoundHandlingOptions}Configuration for file-based asset routing - see docs for options
Pipelines
pipelines?: Record<string, PipelineOptions> | string[]Record mapping binding name to a Pipeline. Different workers may bind to the same Pipeline with different bindings names. If a
string[]of pipeline names, the binding and Pipeline name are assumed to be the same.
Workflows
workflows?: WorkflowOptions[]Configuration for one or more Workflows in your project.
Browser Rendering
browserRendering: BrowserRenderingOptions
Analytics Engine, Sending Email, Vectorize and Workers for Platforms
Not yet supported
If you need support for these locally, consider using the wrappedBindings
option to mock them out.
Workers AI
Not yet supported
If you need support for these locally, consider using the serviceBindings
option to mock them out.
interface SharedOptions
Options shared between all Workers/"nanoservices".
Core
rootPath?: stringPath against which all other path options for this instance are resolved relative to. Defaults to the current working directory.
host?: stringHostname that the
workerdserver should listen on. Defaults to127.0.0.1.port?: numberPort that the
workerdserver should listen on. Tries to default to8787, but falls back to a random free port if this is in use. Note if a manually specified port is in use, Miniflare throws an error, rather than attempting to find a free port.https?: booleanIf
true, start an HTTPS server using a pre-generated self-signed certificate forlocalhost. Note this certificate is not valid for any other hostnames or IP addresses. If you need to access the HTTPS server from another device, you'll need to generate your own certificate and use the otherhttps*options below.$ openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out cert.pemnew Miniflare({ httpsKeyPath: "key.pem", httpsCertPath: "cert.pem", });httpsKey?: stringWhen one of
httpsCertorhttpCertPathis also specified, starts an HTTPS server using the value of this option as the PEM encoded private key.httpsKeyPath?: stringWhen one of
httpsCertorhttpCertPathis also specified, starts an HTTPS server using the PEM encoded private key stored at this file path.httpsCert?: stringWhen one of
httpsKeyorhttpsKeyPathis also specified, starts an HTTPS server using the value of this option as the PEM encoded certificate chain.httpsCertPath?: stringWhen one of
httpsKeyorhttpsKeyPathis also specified, starts an HTTPS server using the PEM encoded certificate chain stored at this file path.inspectorPort?: numberPort that
workerdshould start a DevTools inspector server on. Visitchrome://inspectin a Chromium-based browser to connect to this. This can be used to see detailedconsole.logs, profile CPU usage, and will eventually allow step-through debugging.verbose?: booleanEnable
workerd's--verboseflag for verbose logging. This can be used to see simplifiedconsole.logs.log?: LogLogger implementation for Miniflare's errors, warnings and informative messages.
upstream?: stringURL to use as the origin for incoming requests. If specified, all incoming
request.urls will be rewritten to start with this string. This is especially useful when testing Workers that act as a proxy, and not as origins themselves.cf?: boolean | string | Record<string, any>Controls the object returned from incoming
Request'scfproperty.- If set to a falsy value, an object with default placeholder values will be used
- If set to an object, that object will be used
- If set to
true, a realcfobject will be fetched from a trusted Cloudflare endpoint and cached innode_modules/.mffor 30 days - If set to a
string, a realcfobject will be fetched and cached at the provided path for 30 days
liveReload?: booleanIf
true, Miniflare will inject a script into HTML responses that automatically reloads the page in-browser whenever the Miniflare instance's options are updated.unsafeDevRegistryPath?: stringPath to the dev registry directory. This allows Miniflare to automatically discover external services and Durable Objects running on another miniflare instance and connect them.
unsafeDevRegistryDurableObjectProxy?: booleanIf
true, Miniflare will automatically proxy requests to Durable Objects bound to external services and register all Workers' Durable Objects in the dev registry.unsafeHandleDevRegistryUpdate?: (registry: WorkerRegistry) => voidCallback invoked when the dev registry is updated with changes to bound services. Receives a copy of the updated registry object. Useful for reacting to external service changes during development.
Cache, Durable Objects, KV, R2 and D1
cachePersist?: PersistenceWhere to persist data cached in default or named caches. See docs for
Persistence.durableObjectsPersist?: PersistenceWhere to persist data stored in Durable Objects. See docs for
Persistence.kvPersist?: PersistenceWhere to persist data stored in KV namespaces. See docs for
Persistence.r2Persist?: PersistenceWhere to persist data stored in R2 buckets. See docs for
Persistence.d1Persist?: PersistenceWhere to persist data stored in D1 databases. See docs for
Persistence.workflowsPersist?: Persistence
Where to persist data stored in Workflows. See docs for Persistence.
Analytics Engine, Sending Email, Vectorize, Workers AI and Workers for Platforms
Not yet supported
type MiniflareOptions
SharedOptions & (WorkerOptions | { workers: WorkerOptions[] })
Miniflare accepts either a single Worker configuration or multiple Worker
configurations in the workers array. When specifying an array of Workers, the
first Worker is designated the entrypoint and will receive all incoming HTTP
requests. Some options are shared between all workers and should always be
defined at the top-level.
class Miniflare
constructor(opts: MiniflareOptions)Creates a Miniflare instance and starts a new
workerdHTTP server listening on the configuredhostandport.setOptions(opts: MiniflareOptions)Updates the configuration for this Miniflare instance and restarts the
workerdserver. Note unlike Miniflare 2, this does not merge the new configuration with the old configuration. Note that calling this function will invalidate any existing values returned by theMiniflare#get*()methods, preventing them from being used.ready: Promise<URL>Returns a
Promisethat resolves with ahttpURLto theworkerdserver once it has started and is able to accept requests.dispatchFetch(input: RequestInfo, init?: RequestInit): Promise<Response>Sends a HTTP request to the
workerdserver, dispatching afetchevent in the entrypoint Worker. Returns aPromisethat resolves with the response. Note that this implicitly waits for thereadyPromiseto resolve, there's no need to do that yourself first. Additionally, the host of the request's URL is always ignored and replaced with theworkerdserver's.getBindings<Env extends Record<string, unknown> = Record<string, unknown>>(workerName?: string): Promise<Env>Returns a
Promisethat resolves with a record mapping binding names to bindings, for all bindings in the Worker with the specifiedworkerName. IfworkerNameis not specified, defaults to the entrypoint Worker.getWorker(workerName?: string): Promise<Fetcher>Returns a
Promisethat resolves with aFetcherpointing to the specifiedworkerName. IfworkerNameis not specified, defaults to the entrypoint Worker. Note thisFetcheruses the experimentalservice_binding_extra_handlerscompatibility flag to exposescheduled()andqueue()methods for dispatchingscheduledandqueueevents.getCaches(): Promise<CacheStorage>Returns a
Promisethat resolves with theCacheStorageinstance of the entrypoint Worker. This means ifcache: falseis set on the entrypoint, calling methods on the resolved value won't do anything.getD1Database(bindingName: string, workerName?: string): Promise<D1Database>Returns a
Promisethat resolves with theD1Databaseinstance corresponding to the specifiedbindingNameofworkerName. NotebindingNamemust not begin with__D1_BETA__. IfworkerNameis not specified, defaults to the entrypoint Worker.getDurableObjectNamespace(bindingName: string, workerName?: string): Promise<DurableObjectNamespace>Returns a
Promisethat resolves with theDurableObjectNamespaceinstance corresponding to the specifiedbindingNameofworkerName. IfworkerNameis not specified, defaults to the entrypoint Worker.getKVNamespace(bindingName: string, workerName?: string): Promise<KVNamespace>Returns a
Promisethat resolves with theKVNamespaceinstance corresponding to the specifiedbindingNameofworkerName. IfworkerNameis not specified, defaults to the entrypoint Worker.getQueueProducer<Body>(bindingName: string, workerName?: string): Promise<Queue<Body>>Returns a
Promisethat resolves with theQueueproducer instance corresponding to the specifiedbindingNameofworkerName. IfworkerNameis not specified, defaults to the entrypoint Worker.getR2Bucket(bindingName: string, workerName?: string): Promise<R2Bucket>Returns a
Promisethat resolves with theR2Bucketproducer instance corresponding to the specifiedbindingNameofworkerName. IfworkerNameis not specified, defaults to the entrypoint Worker.dispose(): Promise<void>Cleans up the Miniflare instance, and shuts down the
workerdserver. Note that after this is called,Miniflare#setOptions()andMiniflare#dispatchFetch()cannot be called. Additionally, calling this function will invalidate any values returned by theMiniflare#get*()methods, preventing them from being used.getCf(): Promise<Record<string, any>>Returns the same object returned from incoming
Request'scfproperty. This object depends on thecfproperty fromSharedOptions.
Configuration
Local workerd
You can override the workerd binary being used by miniflare with a your own local build by setting the MINIFLARE_WORKERD_PATH environment variable.
For example:
$ export MINIFLARE_WORKERD_PATH="<WORKERD_REPO_DIR>/bazel-bin/src/workerd/server/workerd"For debugging purposes, you can also set MINIFLARE_WORKERD_CONFIG_DEBUG=<file_path> which will dump the workerd config to the specified file path.