TL;DR: Cloudflare Workers is a serverless execution environment that runs JavaScript at the edge, in over 330 cities worldwide. This guide covers the Workers runtime, Wrangler CLI setup, project structure, local development, and deployment. Full tutorial at tanstackship.com.
Introduction
Cloudflare Workers runs your code on Cloudflare's global network, automatically scaling from zero to millions of requests. Unlike traditional serverless (AWS Lambda), Workers runs in every data center simultaneously, giving you compute within milliseconds of every user. For a detailed comparison of edge computing platforms, see our Edge Computing: Workers vs Lambda@Edge guide.
Wrangler CLI Setup
# Install Wrangler globally
npm install -g wrangler
# Login to your Cloudflare account
wrangler login
# Create a new Workers project
npx create-cloudflare my-worker
# Start local development
wrangler dev
# Deploy to production
wrangler deploy
Basic Worker
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const url = new URL(request.url)
if (url.pathname === '/api/hello') {
return new Response(JSON.stringify({ message: 'Hello from the edge!' }), {
headers: { 'Content-Type': 'application/json' },
})
}
return new Response('Not Found', { status: 404 })
},
}
Workers vs Other Compute
| Platform | Cold Start | Location | Memory | Pricing |
|---|---|---|---|---|
| Cloudflare Workers | <5ms | 330+ locations | 128MB | $0.30/million req |
| AWS Lambda | 200ms-1s | Regions | 10GB | $0.20/million req |
| Vercel Edge | <50ms | 100+ locations | 128MB | Included |
| Deno Deploy | <10ms | 35+ locations | 256MB | $0.10/million req |
Conclusion
Cloudflare Workers provides the fastest serverless runtime available. With near-zero cold starts and global distribution, it's ideal for APIs, middleware, and SSR. Combined with TanStack Start, you get a full-stack framework running on Workers. For production deployment, follow our TanStack Start Deployment Guide. And to properly configure your TypeScript environment, check the Cloudflare Workers TypeScript Setup guide.