Tutorial

Cloudflare Workers Tutorial for Beginners: Deploy Your First Edge Tool

By SpunkArt (@SpunkArt13) · February 22, 2026 · 5 min read

Cloudflare Workers let you run JavaScript at the edge — on Cloudflare's global network of 300+ data centers — without managing a single server. They're fast, they scale automatically, and the free tier gives you 100,000 requests per day. If you've never used them before, this tutorial will get you from zero to deployed in under 10 minutes.

What Are Cloudflare Workers?

Workers are serverless functions that execute on Cloudflare's edge network. When someone makes a request to your Worker, it runs in the data center closest to the user — not in a centralized region like traditional cloud functions. This means lower latency and faster response times for users everywhere in the world.

Think of Workers as lightweight API endpoints. They can:

Unlike traditional servers, you don't pay for idle time. You pay per request (and the first 100,000 per day are free). There's no cold start problem like AWS Lambda — Workers spin up in under 5 milliseconds.

Prerequisites

You'll need three things:

  1. A free Cloudflare account — Sign up at cloudflare.com
  2. Node.js installed — Version 16 or later
  3. A terminal — Any command line will work

Step-by-Step: Deploy Your First Worker

1

Install Wrangler (the Cloudflare CLI)

Wrangler is the official CLI for building and deploying Workers.

npm install -g wrangler

Once installed, authenticate with your Cloudflare account:

wrangler login

This opens your browser. Click "Allow" to connect Wrangler to your account.

2

Create a New Worker Project

Generate a fresh project scaffold:

wrangler init my-first-worker
cd my-first-worker

Select "Hello World" when prompted for a template. This creates a minimal Worker with one file: src/index.js.

3

Write Your Worker Logic

Open src/index.js and replace the contents with a simple JSON API:

export default {
  async fetch(request) {
    const url = new URL(request.url);

    // Simple routing
    if (url.pathname === "/api/hello") {
      return new Response(
        JSON.stringify({
          message: "Hello from the edge!",
          timestamp: new Date().toISOString(),
          location: request.cf?.colo || "unknown"
        }),
        {
          headers: {
            "Content-Type": "application/json",
            "Access-Control-Allow-Origin": "*"
          }
        }
      );
    }

    // Default response
    return new Response("My First Cloudflare Worker", {
      headers: { "Content-Type": "text/plain" }
    });
  }
};

This Worker responds to /api/hello with a JSON payload that includes the Cloudflare data center code serving the request. Every other path returns a plain text greeting.

4

Test Locally

Run the Worker on your machine before deploying:

wrangler dev

Open http://localhost:8787/api/hello in your browser. You should see the JSON response. Make changes to the code and they'll hot-reload instantly.

5

Deploy to Production

When you're ready, deploy with one command:

wrangler deploy

Wrangler outputs your live URL, something like my-first-worker.your-subdomain.workers.dev. Your Worker is now running on Cloudflare's global network. Every request hits the nearest edge node automatically.

What to Build Next

Now that you've deployed your first Worker, here are practical projects to try next:

Each of these projects is already built, tested, and ready to deploy in the SpunkArt Store. The collection includes 18 Cloudflare Workers covering the most common use cases.

Skip the Tutorial — Deploy 18 Workers Today

SpunkArt's complete collection includes password generators, URL shorteners, PDF tools, rate limiters, and more. Production-ready code, one-click deploy, full documentation.

Browse All 18 Workers

Key Concepts to Learn

As you build more Workers, these concepts will become important:

Cloudflare's free tier is generous enough to run serious production tools. SpunkArt runs its entire 18-tool suite and multiple sites on Workers, with zero infrastructure costs.

Further Reading

If you want to understand the broader strategy of building an entire business on top of free hosting and edge computing, read the full case study: How I Built 120+ Websites in 7 Days Using AI.

For the complete playbook with source code and deployment scripts, grab the SpunkArt Ebook. And follow @SpunkArt13 for new tutorials and tool launches.

Get More Tutorials

Step-by-step guides on Workers, edge computing, and building with AI. No spam.

SPUNK.CODES