infrastructure//Cloudflare//Wrangler

Wrangler is Cloudflare's command-line tool: it runs the whole platform (frontend, backend and database) on the local machine and deploys to it from the terminal.


Wrangler is Cloudflare's command-line tool: it runs the whole platform (frontend, backend and database) on the local machine and deploys to it from the terminal.

Wrangler is Cloudflare's platform CLI, as vercel is Vercel's and netlify is Netlify's, the bridge between the developer's machine and Cloudflare: the same code that runs on localhost:8788 is exactly what will run in production, with nothing to change.

It manages Workers, Pages, D1, R2, KV and all the other Cloudflare services from the terminal.

It is configured through wrangler.toml, authenticates through wrangler login (an OAuth flow) and runs through npx (npx wrangler dev) without a global installation.

All the backend code is TypeScript: CRUD routes, SQL queries to D1 and automations (creating a contact also creates its associated story, all in the same handler).

In production, wrangler pages deploy dist uploads the dist/ contents to Pages, and Cloudflare distributes them to the edge, a direct deploy that reaches production with no CI/CD in between. Each request spins up a Worker that is born, executes the backend (Hono), responds and dies (serverless), with no process running 24/7. wrangler d1 migrations apply --remote applies the migrations to the production D1.

In development, wrangler pages dev dist simulates Cloudflare on the local machine at localhost:8788. It acts as a local server like Node.js or Express would, but runs the code in an environment that mimics Workers, with the same result as production.

It serves the frontend (from dist/), the backend (functions/) and a local D1, all on one port. It has HMR for functions (a changed handler reloads), but none for the frontend, which it serves pre-compiled, so the frontend needs a manual rebuild.

Two-terminal mode is the recommended setup for development. Terminal 1 runs Vite (npm run dev, port 5173) for the frontend with HMR, terminal 2 runs Wrangler (wrangler pages dev dist, port 8788) for the API and D1 only, and Vite proxies /api/* to Wrangler. The browser opens localhost:5173, not 8788.

In two-terminal mode Wrangler does not actually need dist/ (it is not serving the frontend), but wrangler pages dev requires a directory argument; if dist/ does not exist, an empty mkdir dist works fine.

A personal note26 · mar 10Read notebuilding a CRM at 2am. wrangler runs all of cloudflare on localhost. frontend, backend, db. i mass years setting up express servers like a peasant. wrangler.toml + npx wrangler dev and you're done.