Wrangler Cheat Sheet: Cloudflare Workers Dev, Deploy, KV, D1 and R2
Checked against Wrangler Wrangler 4.169.0 (npm, 27 Nov 2026); docs read 28 Nov 2026 on 28 November 2026. Each section links to the official docs it was checked against.
This sheet is for people shipping Cloudflare Workers who want the Wrangler commands and config keys in one place. It follows the Wrangler docs on developers.cloudflare.com as read on 28 November 2026, when npm listed Wrangler 4.169.0. Wrangler isn't installed on the machine this was written on, so every row is marked as checked against the docs only.
When to use what
Run Wrangler through the project's package manager (npx wrangler, pnpm wrangler) rather than a global install, so everyone on the team gets the version pinned in package.json. For new projects Cloudflare recommends wrangler.jsonc over wrangler.toml; the keys are the same, so pick JSONC unless you already have a TOML file you like.
wrangler dev is the daily loop. Add --remote only when you need real bindings on Cloudflare's network, and --local when you want to be sure nothing touches remote resources. For shipping, plain wrangler deploy is fine for a side project. On anything with users I prefer wrangler versions upload followed by wrangler versions deploy, because you can send 10% of traffic to the new version first, and wrangler rollback is there when it goes wrong.
For data, the storage commands (kv, d1, r2) all take --local or --remote. The docs pages don't promise one default across all of them, so type the flag every time; it costs two words and saves you from writing test rows into production. If you drive Cloudflare from an AI assistant, the Cloudflare MCP server covers some of the same ground, and our post on Cloudflare Tunnel for local development helps when a Worker needs to reach something on your laptop.
All commands follow the pattern wrangler <command> <subcommand> [options].
npx wrangler init my-workerScaffold a new project using the create-cloudflare (C3) tool
npx wrangler devRun the Worker locally while you edit, with hot reload
npx wrangler dev --remoteRun in a preview on Cloudflare with bindings connected to remote resources
npx wrangler dev --local --port 8788Run only on your machine with all remote bindings disabled, on a chosen port
npx wrangler deployBundle and deploy the Worker described in the config file
npx wrangler deploy --env stagingDeploy using the env.staging block of the config
npx wrangler deploy --dry-run --outdir distCompile and write the bundle to dist without deploying anything
npx wrangler types --checkExit 1 in CI when generated binding types are out of date
Bindings (vars, kv_namespaces, d1_databases, r2_buckets) are not inherited by environments. Repeat them inside each env.<name> block or that environment deploys without them.
"name", "main", "compatibility_date"The three keys a Worker needs before it can deploy (main is optional for assets-only Workers)
"vars": { "API_HOST": "example.com" }Plain-text environment variables; use secrets for anything sensitive
"kv_namespaces": [{ "binding": "CACHE", "id": "<KV_ID>" }]Expose a KV namespace to the Worker as env.CACHE
"d1_databases": [{ "binding": "DB", "database_name": "app", "database_id": "<ID>" }]Bind a D1 database; the ID comes from wrangler d1 create
"r2_buckets": [{ "binding": "FILES", "bucket_name": "uploads" }]Bind an R2 bucket so the Worker can read and write objects
"triggers": { "crons": ["0 3 * * *"] }Run the scheduled handler on a cron schedule; set crons to [] to switch it off
"env": { "staging": { "name": "my-worker-staging" } }Define a named environment that --env staging selects
Each secret command creates a new Worker version and deploys it straight away.
npx wrangler secret put STRIPE_KEYSet a secret; Wrangler prompts for the value or reads it from stdin
npx wrangler secret list --format prettyList secret names in readable form (the default format is JSON)
npx wrangler secret delete STRIPE_KEYRemove a secret from the deployed Worker
npx wrangler secret bulk secrets.jsonUpload up to 100 secrets at once from a JSON or .env file
npx wrangler kv namespace create CACHECreate a namespace and print the ID to paste into the config
npx wrangler kv key put greeting hello --binding CACHE --remoteWrite one key to the real namespace behind the CACHE binding
npx wrangler kv key get greeting --binding CACHE --remote --textRead a key back and print it as text
npx wrangler kv key list --binding CACHE --prefix user: --localList keys starting with user: in local dev storage
npx wrangler kv bulk put data.json --binding CACHE --remoteWrite many keys from one JSON file
d1 execute needs either --command or --file. Time Travel commands always act on the remote database.
npx wrangler d1 create appCreate a database and print the binding and UUID for your config
npx wrangler d1 execute app --local --command "SELECT count(*) FROM users"Run one query against the local copy used by wrangler dev
npx wrangler d1 execute app --remote --file schema.sqlRun a SQL file against the production database
npx wrangler d1 migrations create app add_usersAdd a new numbered SQL file to the migrations folder
npx wrangler d1 migrations list app --remoteShow migrations not yet applied to the remote database
npx wrangler d1 migrations apply app --remoteApply pending migrations after a confirmation prompt; a failed one is rolled back
npx wrangler d1 export app --remote --output backup.sqlDump schema and data to a SQL file (--no-data for schema only)
Object paths are written bucket/key.
npx wrangler r2 bucket create uploadsCreate a new R2 bucket
npx wrangler r2 bucket listList the buckets in your account
npx wrangler r2 object put uploads/img/logo.png --file ./logo.png --content-type image/png --remoteUpload a local file as an object with an explicit content type
npx wrangler r2 object get uploads/img/logo.png --pipe --remoteStream an object to stdout instead of saving it
npx wrangler r2 object delete uploads/img/logo.png --remoteDelete one object from the bucket
npx wrangler tail my-worker --format prettyStream live logs from the deployed Worker in readable form
npx wrangler tail my-worker --status error --search checkoutShow only failed requests whose console output mentions checkout
npx wrangler versions upload --message "new pricing"Upload a version without sending any traffic to it
npx wrangler versions deploy <new-id>@10% <old-id>@90% -ySplit traffic between two versions for a gradual rollout
npx wrangler rollbackMake the version before the latest one active again, immediately
Worked example: Add a D1 table and ship it behind a 10% rollout
Say the Worker already has a D1 binding called DB for a database named app, and you need a new table.
npx wrangler d1 migrations create app add_orders
# edit migrations/000X_add_orders.sql
npx wrangler d1 migrations apply app --local
npx wrangler dev
npx wrangler d1 migrations apply app --remote
npx wrangler versions upload --message "orders table"
npx wrangler versions deploy <new-id>@10% <old-id>@90% -y
npx wrangler tail --status error
The first command only creates an empty numbered SQL file; write the CREATE TABLE in it yourself. Applying it with --local first lets you test against wrangler dev without touching production. When you apply with --remote, Wrangler lists the pending files and asks you to confirm, and the docs say a failed migration is rolled back. Then upload the code as a version, give it 10% of traffic, and watch tail for errors. If the error count climbs, wrangler rollback returns traffic to the previous version. I couldn't run this here, so I'm not showing output; look for the version ID printed by versions upload and use it in the deploy step.
Common mistakes
Adding a KV or D1 binding at the top level and expecting
--env productionto pick it up.Bindings and
varsdon't inherit. Copy them into eachenv.<name>block, with that environment's own IDs.Commenting out the
cronsline to stop a scheduled Worker.The docs say to set
cronsto an empty array and deploy; removing the key doesn't clear the schedule.Running
d1 executeorkv key putwithout saying where, then hunting for the row in the wrong database.Always pass
--localor--remoteso the target is visible in your shell history.Putting API keys in
varsbecause it was quicker than a secret.varssit in the config file in plain text. Usewrangler secret putand keep the value out of git.Using
wrangler deployfor a risky change and having no easy way to test on part of the traffic.Use
versions uploadplusversions deploywith percentages, and keepwrangler rollbackready.
Related cheat sheets
Sources
- https://developers.cloudflare.com/workers/wrangler/commands/workers/
- https://developers.cloudflare.com/workers/wrangler/configuration/
- https://developers.cloudflare.com/workers/wrangler/commands/kv/
- https://developers.cloudflare.com/workers/wrangler/commands/d1/
- https://developers.cloudflare.com/workers/wrangler/commands/r2/
- https://registry.npmjs.org/wrangler/latest
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.