Cloudflare Operations
Cloudflare Workers + Wrangler: runtime patterns, bindings, local dev, secrets, deploy, CI/CD, observability.
Ecosystem facts verified as of 2026-07.
Version context (verified 2026-07): Wrangler v4.x · config is wrangler.jsonc (Cloudflare's recommended format for new projects — some newer features are JSON-config-only; wrangler.toml still works and is widespread in older repos) · deploy command is wrangler deploy (the old wrangler publish is deprecated — see gotchas). Workers can now serve static assets, which is the current direction for full-stack and static sites over Pages (see Workers vs Pages).
Reference Files
| File |
Covers |
| references/bindings.md |
Every binding (KV/D1/R2/DO/Queues/Hyperdrive/AI/Vectorize/Service/Analytics Engine) — config block, runtime API, when to reach for each, consistency model |
| references/workers-runtime.md |
Runtime APIs, handlers (fetch/scheduled/queue/email/tail), CORS, caching, streaming, WebSockets, Durable Objects deep-dive, limits |
| references/workers-runtime-gotchas.md |
Production footguns: detached fetch ("Illegal invocation"), per-colo caches vs KV vs D1, waitUntil semantics + outbox pattern, testing cron handlers, test-workerd lagging production, Email Service account states, Smart Placement, wrangler dev host rewriting |
| references/deploy-and-cicd.md |
wrangler deploy, environments, secrets, Workers Builds, GitHub Actions + OIDC/API-token, gradual deployments, rollbacks, observability |
| assets/wrangler.jsonc.template |
Commented, current wrangler.jsonc covering all common bindings + assets |
Access / Zero Trust auth patterns (verifying Cf-Access-Jwt-Assertion, AUD tags, service auth, closed origins) → auth-ops skill, references/cloudflare-access.md.
Workers vs Pages Decision
Cloudflare added static-asset hosting to Workers; a single Worker now serves a static site, a full-stack app, or an API + SPA. For new projects, default to Workers with static assets. Pages still works and isn't deprecated, but Workers has the broader, faster-moving feature set (Durable Objects, Cron Triggers, Queues, richer observability) and is where Cloudflare's investment goes.
New project?
│
├─ Pure static site (no server logic)
│ └─ Workers + assets binding (asset-only — requests matching files never invoke Worker code, $0 for those).
│ Pages is also fine here; Workers keeps one platform if you later add logic.
│
├─ Full-stack / SPA + API / SSR framework (Next, Astro, Remix, SvelteKit, Hono)
│ └─ Workers + assets + a Worker script. Use the framework's Cloudflare adapter (C3: `npm create cloudflare@latest`).
│ This is the current recommended path — Pages' framework story is converging into Workers.
│
├─ Already on Pages and happy
│ └─ Stay. "What works in Pages works in Workers" — migrate only when you need a Workers-only
│ feature (DO, Cron, Queues, advanced observability). See the migrate-from-pages guide.
│
└─ Need Durable Objects / Cron Triggers / Queues / Tail Workers
└─ Workers (these are Workers-only).
Asset serving modes (in the assets block): asset-only (no main) serves files directly and never bills Worker invocations for matches; assets + Worker serves matching files first, falls through to your fetch handler for everything else (or set run_worker_first to invoke the Worker before asset matching). Reach assets from code via env.ASSETS.fetch(request).
Wrangler Config Skeleton (jsonc)
Full annotated version: assets/wrangler.jsonc.template.
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "my-worker",
"main": "src/index.ts",
"compatibility_date": "2026-06-01", // pins the runtime version — REQUIRED, bump deliberately
"compatibility_flags": ["nodejs_compat"], // opt-in runtime features (Node built-ins, etc.)
"observability": { "enabled": true }, // turn on Workers Logs (off by default)
"assets": { "directory": "./public", "binding": "ASSETS" },
"kv_namespaces": [{ "binding": "CACHE", "id": "<kv-id>" }],
"d1_databases": [{ "binding": "DB", "database_name": "app", "database_id": "<d1-id>" }],
"r2_buckets": [{ "binding": "BUCKET", "bucket_name": "uploads" }],
"vars": { "ENVIRONMENT": "production" }, // NON-secret config only — never put secrets here
"env": {
"staging": { "vars": { "ENVIRONMENT": "staging" } } // named env: deploy with --env staging
}
}
compatibility_date = yyyy-mm-dd, selects the runtime version. It's required and load-bearing: bumping it can change behaviour, so do it deliberately and test. compatibility_flags opt into upcoming/Node-compat features (e.g. nodejs_compat).
- Keep secrets OUT of
vars — they land in plaintext in the deployed config. Use wrangler secret put / .dev.vars (secrets).
- TOML equivalent still parses; the binding shapes map 1:1 (
[[kv_namespaces]], [[d1_databases]], …). New repos: prefer jsonc.
Bindings Table — When Each
Full config + runtime API for every binding: references/bindings.md.
| Binding |
Reach for it when… |
Consistency / note |
| KV |
Read-heavy config/cache, infrequent writes, global reads |
Eventually consistent (~60s propagation). Fast reads, slow-ish writes. Not for "read your own write". |
| D1 |
Relational/SQL data, moderate scale, per-app database |
SQLite at the edge. Strong within a DB; read replication is async. Use for app data with joins. |
| R2 |
Object/blob storage, large files, zero egress fees |
S3-compatible. Replaces S3 for media/backups/assets you serve. |
| Durable Objects |
Strong consistency, coordination, stateful realtime (chat, presence, game rooms, rate limit counters) |
Single-threaded per object instance = serialized = consistent. The answer when KV's eventual consistency bites. SQLite-backed storage available. |
| Queues |
Async/background work, decoupling, batching, retries |
Producer binding + consumer Worker. Smooths spikes; guaranteed delivery with retries + DLQ. |
| Hyperdrive |
Connecting to an existing external Postgres/MySQL with pooling + edge caching |
Makes a regional DB feel fast from Workers. Needs nodejs_compat. |
| Workers AI |
Run inference (LLM, embeddings, image) on Cloudflare's GPUs |
ai binding → env.AI.run(model, ...). Pairs with Vectorize for RAG. |
| Vectorize |
Vector DB for embeddings / semantic search / RAG |
vectorize binding. Store + query embeddings, often fed by Workers AI. |
| Service bindings |
Worker-to-Worker RPC without a network hop |
Zero-latency internal calls; compose Workers as services. |
Decision shortcut: need strong consistency or coordination → Durable Objects. Relational queries → D1. Big files → R2. Cheap global cache → KV. Background work → Queues. External SQL DB → Hyperdrive.
Minimal Worker
export default {
async fetch(request, env, ctx) {
const url = new URL(request.url);
if (url.pathname === "/health") return Response.json({ ok: true });
return new Response("Hello from the edge");
},
};
env carries every binding (env.DB, env.CACHE, env.ASSETS, secrets, vars). ctx.waitUntil(promise) runs background work after the response is sent. Workers require ES module format (export default { fetch }) — the old service-worker addEventListener("fetch") format is legacy. Full handler patterns (scheduled/queue/email/tail, CORS, caching, WebSockets, DO): references/workers-runtime.md.
Local Dev & Secrets
npm create cloudflare@latest my-app # C3 scaffolder — picks framework + adapter + wrangler.jsonc
wrangler dev # local dev server (Miniflare/workerd) on localhost:8787
wrangler dev --remote # run on Cloudflare's edge (real bindings) instead of local sim
wrangler types # generate TS types for env from your bindings → worker-configuration.d.ts
Secrets (never in vars):
| Where |
Mechanism |
| Local dev |
.dev.vars file (dotenv format, gitignored) — wrangler dev loads it as env.*. Per-env: .dev.vars.staging. |
| Deployed |
wrangler secret put NAME (prompts for value, encrypts it) · wrangler secret list · wrangler secret delete NAME |
| CI bulk |
wrangler secret bulk secrets.json |
| Newer |
Cloudflare Secrets Store bindings (account-level shared secrets) — see deploy reference |
Add .dev.vars* to .gitignore. vars in config = plaintext public config; secrets are encrypted and write-only.
Deploy & CI/CD
Full detail: references/deploy-and-cicd.md.
wrangler deploy # build + upload + activate (NOT `wrangler publish` — deprecated)
wrangler deploy --env staging # deploy a named environment
wrangler versions upload # upload a new version WITHOUT making it live (gradual deploys)
wrangler versions deploy # split traffic across versions (e.g. 10% new / 90% old)
wrangler rollback # revert to the previous deployed version
wrangler tail # stream live logs from the deployed Worker
- Workers Builds — Cloudflare's native git-connected CI: push to GitHub/GitLab, Cloudflare builds + deploys. Zero-config for simple Workers; the default for most teams.
- GitHub Actions —
cloudflare/wrangler-action. Authenticate with a scoped API token (CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID as secrets), least-privilege (Workers Scripts:Edit). Template + workflow in the deploy reference.
- Gradual deployments —
versions upload then versions deploy to shift a percentage of traffic; instant rollback if metrics regress.
Observability
"observability": { "enabled": true } in config turns on Workers Logs (structured console.log capture in the dashboard) — off by default, opt in.
wrangler tail for live request log streaming during an incident.
- Tail Workers — a Worker that receives execution traces of another Worker (centralised logging/alerting).
- Analytics Engine — write custom time-series metrics from a Worker (
env.AE.writeDataPoint(...)), query via GraphQL/SQL API.
Common Gotchas
Runtime-level footguns that pass tests and ship — detached fetch ("Illegal invocation"), per-colo caches, waitUntil guarantees, cron testing, the test workerd lagging production, Email Service account states, Smart Placement, wrangler dev rewriting the request host — each with symptom/why/fix: references/workers-runtime-gotchas.md.
| Gotcha |
Detail |
Fix |
wrangler publish is gone |
Renamed to wrangler deploy (Wrangler v3+). Old tutorials/CI still say publish. |
Use wrangler deploy. Update any publish in scripts/CI. |
wrangler.toml vs .jsonc |
Both parse, but newer features are JSON-config-only and Cloudflare recommends jsonc for new projects. |
New projects: wrangler.jsonc. Migrating: wrangler.toml → jsonc is a mechanical 1:1. |
Missing compatibility_date |
Required; absent or stale date silently pins old runtime behaviour. |
Set it; bump deliberately and test — it can change semantics. |
| CPU time limit |
Default 30s CPU per invocation (was 10ms/50ms historically; raised). Wall-clock can be longer while awaiting I/O. CPU-bound loops still get killed. |
Offload heavy compute; use Queues for long async work; check the limits page for your plan. |
| Script size limit |
3 MB (free) / 10 MB (paid) gzipped. |
Trim deps, dynamic-import large modules, avoid bundling node-only libs. |
| KV eventual consistency |
A write isn't globally visible for up to ~60s; not "read your own write". |
Use Durable Objects when you need strong consistency. |
| Node built-ins fail |
fs, crypto, etc. aren't there by default. |
"compatibility_flags": ["nodejs_compat"] enables a polyfill subset; check what's actually supported. |
Secrets in vars |
vars ships plaintext in the deployed config. |
wrangler secret put (deployed) / .dev.vars (local). |
request/response body read twice |
Streams are single-use. |
request.clone() before the first read. |
| Bundling surprises |
Wrangler uses esbuild; some packages assume Node/CommonJS. |
Prefer Workers-compatible libs; set nodejs_compat; check the build output. |
Setup
- Install:
npm install -g wrangler (or use npx wrangler / npm create cloudflare@latest to scaffold).
- Auth:
wrangler login (OAuth) for local; API token for CI.
- Copy assets/wrangler.jsonc.template, strip the bindings you don't need, fill in IDs.
wrangler dev → wrangler deploy.
Staleness verifier
This skill encodes fast-moving facts (Wrangler major line, recommended compatibility_date, wrangler.jsonc config convention). scripts/check-cloudflare-facts.py guards them against silent drift:
# Structural (PR CI, no network): every catalogued fact's prose_token is still
# named in this skill's prose (incl. the jsonc template), and the currency
# note still carries a year.
python scripts/check-cloudflare-facts.py --offline # exit 0 consistent, 10 drift
# Live (freshness job, never blocks a PR): wrangler still resolves on npm and
# its latest major matches the documented v4.x line.
python scripts/check-cloudflare-facts.py --live # exit 10 major drift, 7 npm unreachable
The canonical fact set lives in assets/cloudflare-facts.json; when the Wrangler major, the recommended compatibility_date, or the config convention changes, update it to match or --offline fails CI.
1---2name: cloudflare-ops3description: Cloudflare Workers + Wrangler edge ops: runtime, bindings, local dev, secrets, deploy/CI, Pages-vs-Workers. Triggers on: cloudflare workers, wrangler, wrangler deploy, wrangler.toml, KV, D1, R2, durable objects, queues, vectorize, compatibility_date, edge functions, illegal invocation, waitUntil, caches API, smart placement, email service, vitest-pool-workers, wrangler dev host.4license: MIT5---67# Cloudflare Operations89Cloudflare Workers + Wrangler: runtime patterns, bindings, local dev, secrets, deploy, CI/CD, observability.1011> Ecosystem facts verified as of 2026-07.1213**Version context (verified 2026-07):** Wrangler **v4.x** · config is **`wrangler.jsonc`** (Cloudflare's recommended format for new projects — some newer features are JSON-config-only; `wrangler.toml` still works and is widespread in older repos) · deploy command is **`wrangler deploy`** (the old **`wrangler publish` is deprecated** — see [gotchas](#common-gotchas)). Workers can now **serve static assets**, which is the current direction for full-stack and static sites over Pages (see [Workers vs Pages](#workers-vs-pages-decision)).1415## Reference Files1617| File | Covers |18|------|--------|19| [references/bindings.md](references/bindings.md) | Every binding (KV/D1/R2/DO/Queues/Hyperdrive/AI/Vectorize/Service/Analytics Engine) — config block, runtime API, when to reach for each, consistency model |20| [references/workers-runtime.md](references/workers-runtime.md) | Runtime APIs, handlers (fetch/scheduled/queue/email/tail), CORS, caching, streaming, WebSockets, Durable Objects deep-dive, limits |21| [references/workers-runtime-gotchas.md](references/workers-runtime-gotchas.md) | Production footguns: detached `fetch` ("Illegal invocation"), per-colo `caches` vs KV vs D1, `waitUntil` semantics + outbox pattern, testing cron handlers, test-workerd lagging production, Email Service account states, Smart Placement, `wrangler dev` host rewriting |22| [references/deploy-and-cicd.md](references/deploy-and-cicd.md) | `wrangler deploy`, environments, secrets, Workers Builds, GitHub Actions + OIDC/API-token, gradual deployments, rollbacks, observability |23| [assets/wrangler.jsonc.template](assets/wrangler.jsonc.template) | Commented, current `wrangler.jsonc` covering all common bindings + assets |2425> Access / Zero Trust auth patterns (verifying `Cf-Access-Jwt-Assertion`, AUD tags, service auth, closed origins) → **auth-ops** skill, `references/cloudflare-access.md`.2627## Workers vs Pages Decision2829Cloudflare added static-asset hosting to Workers; a single Worker now serves a static site, a full-stack app, or an API + SPA. **For new projects, default to Workers with static assets.** Pages still works and isn't deprecated, but Workers has the broader, faster-moving feature set (Durable Objects, Cron Triggers, Queues, richer observability) and is where Cloudflare's investment goes.3031```32New project?33│34├─ Pure static site (no server logic)35│ └─ Workers + assets binding (asset-only — requests matching files never invoke Worker code, $0 for those).36│ Pages is also fine here; Workers keeps one platform if you later add logic.37│38├─ Full-stack / SPA + API / SSR framework (Next, Astro, Remix, SvelteKit, Hono)39│ └─ Workers + assets + a Worker script. Use the framework's Cloudflare adapter (C3: `npm create cloudflare@latest`).40│ This is the current recommended path — Pages' framework story is converging into Workers.41│42├─ Already on Pages and happy43│ └─ Stay. "What works in Pages works in Workers" — migrate only when you need a Workers-only44│ feature (DO, Cron, Queues, advanced observability). See the migrate-from-pages guide.45│46└─ Need Durable Objects / Cron Triggers / Queues / Tail Workers47 └─ Workers (these are Workers-only).48```4950**Asset serving modes** (in the `assets` block): asset-only (no `main`) serves files directly and never bills Worker invocations for matches; **assets + Worker** serves matching files first, falls through to your `fetch` handler for everything else (or set `run_worker_first` to invoke the Worker before asset matching). Reach assets from code via `env.ASSETS.fetch(request)`.5152## Wrangler Config Skeleton (jsonc)5354Full annotated version: [assets/wrangler.jsonc.template](assets/wrangler.jsonc.template).5556```jsonc57{58 "$schema": "node_modules/wrangler/config-schema.json",59 "name": "my-worker",60 "main": "src/index.ts",61 "compatibility_date": "2026-06-01", // pins the runtime version — REQUIRED, bump deliberately62 "compatibility_flags": ["nodejs_compat"], // opt-in runtime features (Node built-ins, etc.)6364 "observability": { "enabled": true }, // turn on Workers Logs (off by default)6566 "assets": { "directory": "./public", "binding": "ASSETS" },6768 "kv_namespaces": [{ "binding": "CACHE", "id": "<kv-id>" }],69 "d1_databases": [{ "binding": "DB", "database_name": "app", "database_id": "<d1-id>" }],70 "r2_buckets": [{ "binding": "BUCKET", "bucket_name": "uploads" }],7172 "vars": { "ENVIRONMENT": "production" }, // NON-secret config only — never put secrets here7374 "env": {75 "staging": { "vars": { "ENVIRONMENT": "staging" } } // named env: deploy with --env staging76 }77}78```7980- **`compatibility_date`** = `yyyy-mm-dd`, selects the runtime version. It's required and load-bearing: bumping it can change behaviour, so do it deliberately and test. **`compatibility_flags`** opt into upcoming/Node-compat features (e.g. `nodejs_compat`).81- Keep secrets OUT of `vars` — they land in plaintext in the deployed config. Use `wrangler secret put` / `.dev.vars` ([secrets](#local-dev--secrets)).82- TOML equivalent still parses; the binding shapes map 1:1 (`[[kv_namespaces]]`, `[[d1_databases]]`, …). New repos: prefer jsonc.8384## Bindings Table — When Each8586Full config + runtime API for every binding: [references/bindings.md](references/bindings.md).8788| Binding | Reach for it when… | Consistency / note |89|---------|--------------------|--------------------|90| **KV** | Read-heavy config/cache, infrequent writes, global reads | **Eventually consistent** (~60s propagation). Fast reads, slow-ish writes. Not for "read your own write". |91| **D1** | Relational/SQL data, moderate scale, per-app database | SQLite at the edge. Strong within a DB; read replication is async. Use for app data with joins. |92| **R2** | Object/blob storage, large files, **zero egress fees** | S3-compatible. Replaces S3 for media/backups/assets you serve. |93| **Durable Objects** | **Strong consistency**, coordination, stateful realtime (chat, presence, game rooms, rate limit counters) | Single-threaded per object instance = serialized = consistent. The answer when KV's eventual consistency bites. SQLite-backed storage available. |94| **Queues** | Async/background work, decoupling, batching, retries | Producer binding + consumer Worker. Smooths spikes; guaranteed delivery with retries + DLQ. |95| **Hyperdrive** | Connecting to an **existing external Postgres/MySQL** with pooling + edge caching | Makes a regional DB feel fast from Workers. Needs `nodejs_compat`. |96| **Workers AI** | Run inference (LLM, embeddings, image) on Cloudflare's GPUs | `ai` binding → `env.AI.run(model, ...)`. Pairs with Vectorize for RAG. |97| **Vectorize** | Vector DB for embeddings / semantic search / RAG | `vectorize` binding. Store + query embeddings, often fed by Workers AI. |98| **Service bindings** | Worker-to-Worker RPC without a network hop | Zero-latency internal calls; compose Workers as services. |99100Decision shortcut: **need strong consistency or coordination → Durable Objects. Relational queries → D1. Big files → R2. Cheap global cache → KV. Background work → Queues. External SQL DB → Hyperdrive.**101102## Minimal Worker103104```javascript105export default {106 async fetch(request, env, ctx) {107 const url = new URL(request.url);108 if (url.pathname === "/health") return Response.json({ ok: true });109 return new Response("Hello from the edge");110 },111};112```113114`env` carries every binding (`env.DB`, `env.CACHE`, `env.ASSETS`, secrets, vars). `ctx.waitUntil(promise)` runs background work after the response is sent. Workers require **ES module** format (`export default { fetch }`) — the old service-worker `addEventListener("fetch")` format is legacy. Full handler patterns (scheduled/queue/email/tail, CORS, caching, WebSockets, DO): [references/workers-runtime.md](references/workers-runtime.md).115116## Local Dev & Secrets117118```bash119npm create cloudflare@latest my-app # C3 scaffolder — picks framework + adapter + wrangler.jsonc120wrangler dev # local dev server (Miniflare/workerd) on localhost:8787121wrangler dev --remote # run on Cloudflare's edge (real bindings) instead of local sim122wrangler types # generate TS types for env from your bindings → worker-configuration.d.ts123```124125**Secrets** (never in `vars`):126127| Where | Mechanism |128|-------|-----------|129| Local dev | **`.dev.vars`** file (dotenv format, gitignored) — `wrangler dev` loads it as `env.*`. Per-env: `.dev.vars.staging`. |130| Deployed | **`wrangler secret put NAME`** (prompts for value, encrypts it) · `wrangler secret list` · `wrangler secret delete NAME` |131| CI bulk | `wrangler secret bulk secrets.json` |132| Newer | Cloudflare **Secrets Store** bindings (account-level shared secrets) — see deploy reference |133134Add `.dev.vars*` to `.gitignore`. `vars` in config = plaintext public config; secrets are encrypted and write-only.135136## Deploy & CI/CD137138Full detail: [references/deploy-and-cicd.md](references/deploy-and-cicd.md).139140```bash141wrangler deploy # build + upload + activate (NOT `wrangler publish` — deprecated)142wrangler deploy --env staging # deploy a named environment143wrangler versions upload # upload a new version WITHOUT making it live (gradual deploys)144wrangler versions deploy # split traffic across versions (e.g. 10% new / 90% old)145wrangler rollback # revert to the previous deployed version146wrangler tail # stream live logs from the deployed Worker147```148149- **Workers Builds** — Cloudflare's native git-connected CI: push to GitHub/GitLab, Cloudflare builds + deploys. Zero-config for simple Workers; the default for most teams.150- **GitHub Actions** — `cloudflare/wrangler-action`. Authenticate with a scoped **API token** (`CLOUDFLARE_API_TOKEN` + `CLOUDFLARE_ACCOUNT_ID` as secrets), least-privilege (Workers Scripts:Edit). Template + workflow in the deploy reference.151- **Gradual deployments** — `versions upload` then `versions deploy` to shift a percentage of traffic; instant `rollback` if metrics regress.152153## Observability154155- `"observability": { "enabled": true }` in config turns on **Workers Logs** (structured `console.log` capture in the dashboard) — **off by default**, opt in.156- `wrangler tail` for live request log streaming during an incident.157- **Tail Workers** — a Worker that receives execution traces of another Worker (centralised logging/alerting).158- **Analytics Engine** — write custom time-series metrics from a Worker (`env.AE.writeDataPoint(...)`), query via GraphQL/SQL API.159160## Common Gotchas161162Runtime-level footguns that pass tests and ship — detached `fetch` ("Illegal invocation"), per-colo `caches`, `waitUntil` guarantees, cron testing, the test workerd lagging production, Email Service account states, Smart Placement, `wrangler dev` rewriting the request host — each with symptom/why/fix: [references/workers-runtime-gotchas.md](references/workers-runtime-gotchas.md).163164| Gotcha | Detail | Fix |165|--------|--------|-----|166| **`wrangler publish` is gone** | Renamed to `wrangler deploy` (Wrangler v3+). Old tutorials/CI still say `publish`. | Use `wrangler deploy`. Update any `publish` in scripts/CI. |167| **`wrangler.toml` vs `.jsonc`** | Both parse, but newer features are JSON-config-only and Cloudflare recommends jsonc for new projects. | New projects: `wrangler.jsonc`. Migrating: `wrangler.toml` → jsonc is a mechanical 1:1. |168| **Missing `compatibility_date`** | Required; absent or stale date silently pins old runtime behaviour. | Set it; bump deliberately and test — it can change semantics. |169| **CPU time limit** | Default **30s** CPU per invocation (was 10ms/50ms historically; raised). Wall-clock can be longer while awaiting I/O. CPU-bound loops still get killed. | Offload heavy compute; use Queues for long async work; check the limits page for your plan. |170| **Script size limit** | 3 MB (free) / 10 MB (paid) gzipped. | Trim deps, dynamic-import large modules, avoid bundling node-only libs. |171| **KV eventual consistency** | A write isn't globally visible for up to ~60s; not "read your own write". | Use **Durable Objects** when you need strong consistency. |172| **Node built-ins fail** | `fs`, `crypto`, etc. aren't there by default. | `"compatibility_flags": ["nodejs_compat"]` enables a polyfill subset; check what's actually supported. |173| **Secrets in `vars`** | `vars` ships plaintext in the deployed config. | `wrangler secret put` (deployed) / `.dev.vars` (local). |174| **`request`/`response` body read twice** | Streams are single-use. | `request.clone()` before the first read. |175| **Bundling surprises** | Wrangler uses esbuild; some packages assume Node/CommonJS. | Prefer Workers-compatible libs; set `nodejs_compat`; check the build output. |176177## Setup1781791. Install: `npm install -g wrangler` (or use `npx wrangler` / `npm create cloudflare@latest` to scaffold).1802. Auth: `wrangler login` (OAuth) for local; **API token** for CI.1813. Copy [assets/wrangler.jsonc.template](assets/wrangler.jsonc.template), strip the bindings you don't need, fill in IDs.1824. `wrangler dev` → `wrangler deploy`.183184## Staleness verifier185186This skill encodes fast-moving facts (Wrangler major line, recommended `compatibility_date`, `wrangler.jsonc` config convention). [`scripts/check-cloudflare-facts.py`](scripts/check-cloudflare-facts.py) guards them against silent drift:187188```bash189# Structural (PR CI, no network): every catalogued fact's prose_token is still190# named in this skill's prose (incl. the jsonc template), and the currency191# note still carries a year.192python scripts/check-cloudflare-facts.py --offline # exit 0 consistent, 10 drift193194# Live (freshness job, never blocks a PR): wrangler still resolves on npm and195# its latest major matches the documented v4.x line.196python scripts/check-cloudflare-facts.py --live # exit 10 major drift, 7 npm unreachable197```198199The canonical fact set lives in [`assets/cloudflare-facts.json`](assets/cloudflare-facts.json); when the Wrangler major, the recommended compatibility_date, or the config convention changes, update it to match or `--offline` fails CI.