Cloudflare WorkersServerlessWranglerGetting Started

Cloudflare Workers: Introduction and Getting Started

Get started with Cloudflare Workers for serverless computing, covering the Workers runtime, Wrangler CLI, project setup, and deployment workflow.

Alex Chen
Alex Chen
June 1, 202610 min read
Also available in:Deutsch · 中文

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

bash
# 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

ts
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

PlatformCold StartLocationMemoryPricing
Cloudflare Workers<5ms330+ locations128MB$0.30/million req
AWS Lambda200ms-1sRegions10GB$0.20/million req
Vercel Edge<50ms100+ locations128MBIncluded
Deno Deploy<10ms35+ locations256MB$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.