Learn Cloudflare Workers

Build serverless applications at the edge with Cloudflare Workers.

What You'll Build

  • HTTP APIs with routing
  • KV storage & caching
  • D1 database applications
  • AI-powered Workers

Prerequisites

  • Node.js v18+
  • Cloudflare Account
  • Terminal/Command Line
  • Basic JavaScript knowledge

Workshop Format

  • 7 hands-on labs
  • Progressive complexity
  • Deploy to global edge

Cloudflare Workers Fundamentals

What is Cloudflare Workers?

Cloudflare Workers is a serverless platform for building, deploying, and scaling applications across Cloudflare's global network with a single command and no infrastructure to manage.

Core Concepts

  • Edge Computing: Code runs at locations closest to users for minimal latency
  • V8 Isolates: Lightweight, secure runtime environment
  • Global Network: Deploy once, run everywhere
  • Serverless: No servers to manage, automatic scaling

What You'll Build

  • HTTP APIs with routing and request handling
  • Key-value storage for user data and caching
  • Database-backed applications with D1 SQL
  • AI-powered features using Workers AI
  • Smart request routing with AI Gateway

Prerequisites

Before starting the workshop, ensure you have:

💻

Node.js v20+

Download from nodejs.org

☁️

Free Cloudflare Account

Sign up here (no credit card needed)

Wrangler CLI

npx wrangler@latest

🧠

Basic TypeScript

Familiarity with Node.js and terminal usage

Ready? Jump into the hands-on workshop below! ⬇️

Workshop Steps

WORKSHOP STEPS
STEP 01

Getting Started with Cloudflare Workers

Create your first Cloudflare Worker and understand the fundamentals of serverless edge computing. Learn about the Workers runtime and deploy your first function.

🎯 Learning Objectives

  • Create and deploy your first Cloudflare Worker
  • Understand the Workers runtime environment
  • Learn about edge computing concepts
  • Test your Worker using Wrangler CLI
🛠️ Understanding Cloudflare Workers

Cloudflare Workers is a serverless platform for building, deploying, and scaling applications across Cloudflare’s global network with a single command and no infrastructure to manage.

  • Edge Computing: Code runs at locations closest to users for minimal latency
  • V8 Isolates: Lightweight, secure runtime environment (not containers)
  • Global Network: Deploy once, run everywhere across Cloudflare’s infrastructure
  • Serverless: No servers to manage, automatic scaling, pay-per-request

Watch: Cloudflare Workers 101

Before diving into the hands-on tutorial, watch this comprehensive overview to understand the core concepts and architecture of Cloudflare Workers. This video covers the fundamentals that will help you better understand building with Cloudflare Workers.

Step 1: Create Your First Worker

What we're building
A simple Cloudflare Worker that responds to HTTP requests with a custom message.
Why this matters
Workers handle HTTP requests at the edge, providing fast responses to users worldwide with minimal setup.
# Create a new Worker project with TypeScript
npm create cloudflare@latest -- my-first-worker --type hello-world --ts

# Navigate to your project
cd my-first-worker

# Start development server
npx wrangler dev
Expected Output text

⎔ Starting local server… [wrangler:info] Ready on http://localhost:8787 🌍 Your Worker is running locally and ready for testing 📝 Edit src/index.ts to see changes in real-time

📝 What Just Happened?

You’ve created a Cloudflare Worker that includes:

  • HTTP Handler: Function that processes incoming requests
  • Local Development: Wrangler dev server for testing
  • Hot Reloading: Changes reflect immediately during development
Troubleshooting
  • npm not found: Install Node.js v20+ from nodejs.org
  • Template not found: Update npm: npm install -g npm@latest
  • Port 8787 busy: Stop other services or use npm run dev -- --port 8788
  • Build errors: Delete node_modules and run npm install again

Step 2: Understanding Your Worker Code

What we're building
Understanding of your Worker's code structure and how it processes HTTP requests.
Why this matters
Understanding the fetch handler is fundamental to building any application with Cloudflare Workers.

Let’s examine the default Worker code that was generated:

// src/index.ts
export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    return new Response('Hello World!');
  },
};
📝 Worker Structure

Every Cloudflare Worker exports a default object with handler functions:

  • fetch: Handles HTTP requests (required for web applications)
  • scheduled: Handles cron triggers (optional)
  • queue: Handles queue messages (optional)
  • email: Handles email events (optional)

The Fetch Handler Parameters:

  • request: Contains the incoming HTTP request (URL, headers, method, body)
  • env: Environment variables and bindings (KV, R2, D1, etc.)
  • ctx: Context object with waitUntil() and passThroughOnException()

Step 3: Test Your Worker

What we're building
A working local development environment where you can test your Worker and see changes in real-time.
Why this matters
Local testing is essential for rapid development and debugging before deploying to production.

Testing Your Worker:

  1. Open your browser and navigate to http://localhost:8787
  2. You should see: “Hello World!” displayed in your browser
  3. Try different URLs like http://localhost:8787/test - same response
  4. Check the terminal for request logs showing method, path, and response time
📝 What You Should See

Your terminal will show logs like:

  • GET / 200 OK (2ms) - successful request
  • Hot reloading when you save file changes
  • Any console.log() output from your Worker

Step 4: Deploy to Production

What we're building
Your first Worker deployed to Cloudflare's global network, accessible via a workers.dev subdomain.
Why this matters
Deploying to production lets you see your Worker running at the edge across Cloudflare's global network.
# Deploy your Worker to production
npx wrangler deploy

After deployment, you’ll see:

  • Your Worker URL: https://my-first-worker.<your-subdomain>.workers.dev
  • Global deployment across 300+ data centers
  • Instant availability worldwide
📝 Production Deployment

Your Worker is now running on Cloudflare’s global network:

  • Global reach: Available from 300+ locations worldwide
  • Automatic scaling: Handles traffic spikes without configuration
  • Zero cold starts: V8 isolates start instantly
  • Built-in security: DDoS protection and security features included

Congratulations! You’ve created and deployed your first Cloudflare Worker. You’re ready to learn HTTP request handling in Step 2!

Learning Resources

Essential resources for mastering Cloudflare Workers and building serverless applications.

📖 Workers Documentation

Official Cloudflare Workers documentation with API references and best practices

READ DOCS

🎥 Developer Channel

Getting started guides and how-to videos for the Developer Platform and AI tools

WATCH VIDEOS

💬 Community

Open community where users can ask questions and share ideas and solutions

JOIN COMMUNITY

🔧 Cloudflare Workers

Deploy your MCP servers globally with Cloudflare Workers documentation

WORKERS DOCS

💾 Cloudflare KV

Learn about key-value storage for building persistent MCP applications

KV DOCS

🤖 Workers AI

Run machine learning models on Cloudflare's global network with Workers AI

EXPLORE AI