Skip to content

Menu

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-worker

Scaffold a new project using the create-cloudflare (C3) tool

From the docs, not run by us
npx wrangler dev

Run the Worker locally while you edit, with hot reload

From the docs, not run by us
npx wrangler dev --remote

Run in a preview on Cloudflare with bindings connected to remote resources

From the docs, not run by us
npx wrangler dev --local --port 8788

Run only on your machine with all remote bindings disabled, on a chosen port

From the docs, not run by us
npx wrangler deploy

Bundle and deploy the Worker described in the config file

From the docs, not run by us
npx wrangler deploy --env staging

Deploy using the env.staging block of the config

From the docs, not run by us
npx wrangler deploy --dry-run --outdir dist

Compile and write the bundle to dist without deploying anything

From the docs, not run by us
npx wrangler types --check

Exit 1 in CI when generated binding types are out of date

From the docs, not run by us

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)

From the docs, not run by us
"vars": { "API_HOST": "example.com" }

Plain-text environment variables; use secrets for anything sensitive

From the docs, not run by us
"kv_namespaces": [{ "binding": "CACHE", "id": "<KV_ID>" }]

Expose a KV namespace to the Worker as env.CACHE

From the docs, not run by us
"d1_databases": [{ "binding": "DB", "database_name": "app", "database_id": "<ID>" }]

Bind a D1 database; the ID comes from wrangler d1 create

From the docs, not run by us
"r2_buckets": [{ "binding": "FILES", "bucket_name": "uploads" }]

Bind an R2 bucket so the Worker can read and write objects

From the docs, not run by us
"triggers": { "crons": ["0 3 * * *"] }

Run the scheduled handler on a cron schedule; set crons to [] to switch it off

Try it: crontab-translatorFrom the docs, not run by us
"env": { "staging": { "name": "my-worker-staging" } }

Define a named environment that --env staging selects

From the docs, not run by us

Each secret command creates a new Worker version and deploys it straight away.

npx wrangler secret put STRIPE_KEY

Set a secret; Wrangler prompts for the value or reads it from stdin

From the docs, not run by us
npx wrangler secret list --format pretty

List secret names in readable form (the default format is JSON)

From the docs, not run by us
npx wrangler secret delete STRIPE_KEY

Remove a secret from the deployed Worker

From the docs, not run by us
npx wrangler secret bulk secrets.json

Upload up to 100 secrets at once from a JSON or .env file

Try it: env-to-jsonFrom the docs, not run by us
npx wrangler kv namespace create CACHE

Create a namespace and print the ID to paste into the config

From the docs, not run by us
npx wrangler kv key put greeting hello --binding CACHE --remote

Write one key to the real namespace behind the CACHE binding

From the docs, not run by us
npx wrangler kv key get greeting --binding CACHE --remote --text

Read a key back and print it as text

From the docs, not run by us
npx wrangler kv key list --binding CACHE --prefix user: --local

List keys starting with user: in local dev storage

From the docs, not run by us
npx wrangler kv bulk put data.json --binding CACHE --remote

Write many keys from one JSON file

From the docs, not run by us

d1 execute needs either --command or --file. Time Travel commands always act on the remote database.

npx wrangler d1 create app

Create a database and print the binding and UUID for your config

From the docs, not run by us
npx wrangler d1 execute app --local --command "SELECT count(*) FROM users"

Run one query against the local copy used by wrangler dev

From the docs, not run by us
npx wrangler d1 execute app --remote --file schema.sql

Run a SQL file against the production database

From the docs, not run by us
npx wrangler d1 migrations create app add_users

Add a new numbered SQL file to the migrations folder

From the docs, not run by us
npx wrangler d1 migrations list app --remote

Show migrations not yet applied to the remote database

From the docs, not run by us
npx wrangler d1 migrations apply app --remote

Apply pending migrations after a confirmation prompt; a failed one is rolled back

From the docs, not run by us
npx wrangler d1 export app --remote --output backup.sql

Dump schema and data to a SQL file (--no-data for schema only)

From the docs, not run by us

Object paths are written bucket/key.

npx wrangler r2 bucket create uploads

Create a new R2 bucket

From the docs, not run by us
npx wrangler r2 bucket list

List the buckets in your account

From the docs, not run by us
npx wrangler r2 object put uploads/img/logo.png --file ./logo.png --content-type image/png --remote

Upload a local file as an object with an explicit content type

From the docs, not run by us
npx wrangler r2 object get uploads/img/logo.png --pipe --remote

Stream an object to stdout instead of saving it

From the docs, not run by us
npx wrangler r2 object delete uploads/img/logo.png --remote

Delete one object from the bucket

From the docs, not run by us
npx wrangler tail my-worker --format pretty

Stream live logs from the deployed Worker in readable form

From the docs, not run by us
npx wrangler tail my-worker --status error --search checkout

Show only failed requests whose console output mentions checkout

From the docs, not run by us
npx wrangler versions upload --message "new pricing"

Upload a version without sending any traffic to it

From the docs, not run by us
npx wrangler versions deploy <new-id>@10% <old-id>@90% -y

Split traffic between two versions for a gradual rollout

From the docs, not run by us
npx wrangler rollback

Make the version before the latest one active again, immediately

From the docs, not run by us

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 production to pick it up.

    Bindings and vars don't inherit. Copy them into each env.<name> block, with that environment's own IDs.

  • Commenting out the crons line to stop a scheduled Worker.

    The docs say to set crons to an empty array and deploy; removing the key doesn't clear the schedule.

  • Running d1 execute or kv key put without saying where, then hunting for the row in the wrong database.

    Always pass --local or --remote so the target is visible in your shell history.

  • Putting API keys in vars because it was quicker than a secret.

    vars sit in the config file in plain text. Use wrangler secret put and keep the value out of git.

  • Using wrangler deploy for a risky change and having no easy way to test on part of the traffic.

    Use versions upload plus versions deploy with percentages, and keep wrangler rollback ready.