100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Cloudflare Workers Cheat Sheet

Cloudflare Workers Cheat Sheet

Build and deploy serverless functions at the edge with Cloudflare Workers, Wrangler CLI, KV storage, and Durable Objects basics.

2 PagesIntermediateJan 28, 2026

Wrangler CLI Basics

Scaffold, develop, and deploy Workers with Wrangler.

bash
npm create cloudflare@latest my-worker   # Scaffold a new Workercd my-workernpx wrangler login                       # Authenticate with Cloudflarenpx wrangler dev                         # Run locally with hot reloadnpx wrangler deploy                      # Deploy to productionnpx wrangler tail                        # Stream live logs from a deployed Workernpx wrangler kv:namespace create MY_KV   # Create a KV namespacenpx wrangler secret put API_KEY          # Store an encrypted secret

Worker Fetch Handler

Basic module-syntax Worker responding to HTTP requests.

javascript
export default {  async fetch(request, env, ctx) {    const url = new URL(request.url);    if (url.pathname === '/api/time') {      return new Response(JSON.stringify({ now: Date.now() }), {        headers: { 'content-type': 'application/json' },      });    }    return new Response('Not found', { status: 404 });  },};

wrangler.toml Config

Declare bindings, routes, and compatibility settings.

yaml
name = "my-worker"main = "src/index.js"compatibility_date = "2024-01-01"[[kv_namespaces]]binding = "MY_KV"id = "abcd1234"[vars]ENVIRONMENT = "production"[[routes]]pattern = "example.com/api/*"zone_name = "example.com"

Core Concepts

Key primitives available in the Workers runtime.

  • env bindings- KV, R2, D1, and secrets are injected into the handler via the `env` parameter, not global variables
  • KV (Workers KV)- eventually-consistent key-value store, accessed via `env.MY_KV.get()` / `.put()`
  • R2- S3-compatible object storage with zero egress fees
  • D1- serverless SQLite database that runs at the edge
  • Durable Objects- stateful, single-instance objects for coordination (e.g. chat rooms, counters)
  • ctx.waitUntil()- extends the Worker's lifetime to finish async work after the response is sent
  • Cron Triggers- scheduled Workers configured via `[triggers] crons = [...]` in wrangler.toml
Pro Tip

Workers have strict CPU-time limits (not wall-clock time), so `ctx.waitUntil()` is the right tool for logging or cache-writes after responding — but any CPU-bound work still counts against your execution limit even inside it.

Was this cheat sheet helpful?

Explore Topics

#CloudflareWorkers#CloudflareWorkersCheatSheet#CloudComputing#Intermediate#WranglerCLIBasics#WorkerFetchHandler#WranglerTomlConfig#CoreConcepts#OOP#Functions#DevOps#CommandLine#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet