Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/miniflare/configuration.md
1# Configuration23## Script Loading45```js6// Inline7new Miniflare({ modules: true, script: `export default { ... }` });89// File-based10new Miniflare({ scriptPath: "worker.js" });1112// Multi-module13new Miniflare({14scriptPath: "src/index.js",15modules: true,16modulesRules: [17{ type: "ESModule", include: ["**/*.js"] },18{ type: "Text", include: ["**/*.txt"] },19],20});21```2223## Compatibility2425```js26new Miniflare({27compatibilityDate: "2026-01-01", // Use recent date for latest features28compatibilityFlags: [29"nodejs_compat", // Node.js APIs (process, Buffer, etc)30"streams_enable_constructors", // Stream constructors31],32upstream: "https://example.com", // Fallback for unhandled requests33});34```3536**Critical:** Use `compatibilityDate: "2026-01-01"` or latest to match production runtime. Old dates limit available APIs.3738## HTTP Server & Request.cf3940```js41new Miniflare({42port: 8787, // Default: 878743host: "127.0.0.1",44https: true, // Self-signed cert45liveReload: true, // Auto-reload HTML4647cf: true, // Fetch live Request.cf data (cached)48// cf: "./cf.json", // Or load from file49// cf: { colo: "DFW" }, // Or inline mock50});51```5253**Note:** For tests, use `dispatchFetch()` (no port conflicts).5455## Storage Bindings5657```js58new Miniflare({59// KV60kvNamespaces: ["TEST_NAMESPACE", "CACHE"],61kvPersist: "./kv-data", // Optional: persist to disk6263// R264r2Buckets: ["BUCKET", "IMAGES"],65r2Persist: "./r2-data",6667// Durable Objects68modules: true,69durableObjects: {70COUNTER: "Counter", // className71API_OBJECT: { className: "ApiObject", scriptName: "api-worker" },72},73durableObjectsPersist: "./do-data",7475// D176d1Databases: ["DB"],77d1Persist: "./d1-data",7879// Cache80cache: true, // Default81cachePersist: "./cache-data",82});83```8485## Bindings8687```js88new Miniflare({89// Environment variables90bindings: {91SECRET_KEY: "my-secret-value",92API_URL: "https://api.example.com",93DEBUG: true,94},9596// Other bindings97wasmBindings: { ADD_MODULE: "./add.wasm" },98textBlobBindings: { TEXT: "./data.txt" },99queueProducers: ["QUEUE"],100});101```102103## Multiple Workers104105```js106new Miniflare({107workers: [108{109name: "main",110kvNamespaces: { DATA: "shared" },111serviceBindings: { API: "api-worker" },112script: `export default { ... }`,113},114{115name: "api-worker",116kvNamespaces: { DATA: "shared" }, // Shared storage117script: `export default { ... }`,118},119],120});121```122123**With routing:**124```js125workers: [126{ name: "api", scriptPath: "./api.js", routes: ["api.example.com/*"] },127{ name: "web", scriptPath: "./web.js", routes: ["example.com/*"] },128],129```130131## Logging & Performance132133```js134import { Log, LogLevel } from "miniflare";135136new Miniflare({137log: new Log(LogLevel.DEBUG), // DEBUG | INFO | WARN | ERROR | NONE138scriptTimeout: 30000, // CPU limit (ms)139workersConcurrencyLimit: 10, // Max concurrent workers140});141```142143## Workers Sites144145```js146new Miniflare({147sitePath: "./public",148siteInclude: ["**/*.html", "**/*.css"],149siteExclude: ["**/*.map"],150});151```152153## From wrangler.toml154155Miniflare doesn't auto-read `wrangler.toml`:156157```toml158# wrangler.toml159name = "my-worker"160main = "src/index.ts"161compatibility_date = "2026-01-01"162[[kv_namespaces]]163binding = "KV"164```165166```js167// Miniflare equivalent168new Miniflare({169scriptPath: "src/index.ts",170compatibilityDate: "2026-01-01",171kvNamespaces: ["KV"],172});173```174