Part 4: Local Dev
In Part 3 you wrote integration tests against
your deployed stack. But deploying to Cloudflare on every code change
is slow. In this part you’ll use alchemy dev to run everything
locally with hot reloading.
Start dev mode
Section titled “Start dev mode”alchemy devThat’s it. Alchemy deploys your stack to the cloud and proxies requests to Workers running locally in workerd. It watches for file changes and hot reloads your Worker automatically.
Your Worker is available at http://localhost:1337 by default:
curl http://localhost:1337/hello.txtHow it works
Section titled “How it works”alchemy dev does three things:
- Deploys to the cloud — resources like R2 Buckets are created on Cloudflare, while Workers run locally in workerd
- Watches for changes — when you edit
src/worker.tsor any file it imports, the Worker is rebuilt and reloaded instantly - Preserves local state — data in your local R2 Bucket persists across restarts
The same alchemy.run.ts is used for both dev and deploy — no
separate dev config needed.
Custom port
Section titled “Custom port”Set a custom port for your Worker:
export default Cloudflare.Worker( "Worker", { main: import.meta.path, dev: { port: 3000, }, }, // ...);Run tests against dev
Section titled “Run tests against dev”Since your Worker runs on localhost in dev mode, you can point your integration tests at it for an even faster feedback loop:
# Terminal 1: start dev modealchemy dev
# Terminal 2: run tests against localbun test test/integ.test.tsThe tests deploy the stack and run HTTP assertions against your local Worker.
You now have:
- Local development with
alchemy dev - Hot reloading on file changes
- Local emulation of Cloudflare resources
In Part 5, you’ll set up GitHub Actions for automated deployments and PR preview environments.