Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
R2 Storage and the Developer Toolchain  ›  Lesson

Wrangler and Miniflare — Build Locally, Ship Globally

Wrangler 12 minWrangler scaffolds, runs, deploys and observes Workers, and its local dev server uses Miniflare to simulate the runtime and bindings on your machine with separate local data.

Wrangler and Miniflare — Build Locally, Ship Globally

Hoplink is about to grow a new feature: letting people attach files to short links. Before touching storage, you need a comfortable loop for writing, running and deploying code. Editing in the dashboard works for a demo, but real projects live in a folder, in Git, driven from the terminal.

The rule

Create, dev, deploy — local first, real network last.

Wrangler is Cloudflare's command-line tool. Four commands carry most of the load:

npm create cloudflare@latest hoplink   # scaffold a new project
npx wrangler dev                        # run it on your machine
npx wrangler deploy                     # publish to the whole network
npx wrangler tail                       # stream live logs from production
  • Create. The scaffolding tool writes wrangler.jsonc, a src/ entry file and package.json, and can set up TypeScript and a framework such as Hono.
  • Dev. wrangler dev serves your Worker at http://localhost:8787. It runs on Miniflare, a local simulator built on workerd, the same open-source runtime that powers production Workers. Your KV, R2, D1, Durable Objects and queues are simulated too, stored under .wrangler/state in the project folder. Nothing you do locally touches real data.
  • Deploy. wrangler deploy bundles your code, uploads it with the bindings from your config, and it is live worldwide within seconds.
  • Observe. wrangler tail shows console.log output and errors from real traffic; wrangler dev also offers a DevTools inspector for breakpoints.

Resources are created from the same tool: wrangler kv namespace create LINKS, wrangler r2 bucket create hop-files, wrangler d1 create hop-db. Each command prints the config snippet to paste into wrangler.jsonc.

In a team, wrangler deploy usually runs from CI rather than a laptop: a pipeline installs dependencies, runs tests, and deploys with an API token stored as a CI secret.

The shortcut

For every change, climb the same ladder and stop at the first rung that proves it: local dev → preview → production. Most bugs die on the first rung, where mistakes are free.

Shipping Hoplink's new file routeStep 1 of 4
  1. Scaffold the resource

    wrangler r2 bucket create hop-files, then add the printed r2_buckets entry to wrangler.jsonc.

Trap: expecting local data to appear in production (or the reverse). Local and remote are separate worlds; commands that act on data usually take --local or --remote so you can choose deliberately.

Drills

Answer fast — trust the rule.

quick drill

Which command runs Hoplink on your own machine with simulated bindings?

quick drill

What is Miniflare?

quick drill

A link created while running wrangler dev does not appear on the deployed site. Why?

quick drill

You want to see errors from real production traffic as they happen. What do you run?

Remember

  • Create, dev, deploy — local first, real network last.
  • Shortcut: climb local → preview → production and stop at the first rung that proves the change.
  • Trap: mixing up local simulated data with remote data.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainFrom laptop to production

Describe the steps, with Wrangler commands, to add an R2 bucket to Hoplink, test an upload route safely, and ship it. Explain why local testing cannot damage real data.