How to debug Cloudflare Workers locally
A reliable method for setting up local Wrangler dev and inspecting requests.
Problem
Testing Cloudflare Workers in production is slow. You want fast feedback loops with wrangler dev.
Solution
- Install Wrangler globally:
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
npm install -g wrangler
- Authenticate once:
wrangler login
- Run the local dev server:
wrangler dev --local
- Add
console.log()statements in your Worker. They appear in the terminal instantly.
Pro tip
Use wrangler tail to stream production logs when you need to inspect live traffic without redeploying.