- Published on
What Is Cloudflare Workers? A 10-Minute Guide for 2026
Cloudflare Workers is a serverless computing platform that allows you to run code instantly across a global network of over 300 cities. By deploying code to the "edge" (servers located physically close to your users), you can reduce website latency to under 50 milliseconds. Most beginners can deploy their first functional API or website redirect in less than 10 minutes using the free tier.
How does edge computing actually work?
Traditional web hosting usually keeps your code in one specific location, like a data center in Virginia or London. When a user in Tokyo visits your site, their request must travel across the ocean, which creates a delay called latency (the time it takes for data to travel).
Cloudflare Workers changes this by using a technology called "Isolates." Instead of running a full virtual machine for every user, it runs small pieces of JavaScript, Rust, or Python code directly on Cloudflare’s global servers.
This means when that user in Tokyo clicks a link, the code executes at a data center in Tokyo. The response is almost instant because the data only travels a few miles instead of thousands.
What are the main benefits for beginners?
One of the biggest hurdles for new developers is managing servers, which involves updating operating systems and configuring security. Cloudflare Workers is "serverless," meaning Cloudflare handles all the hardware and scaling for you automatically.
If your project suddenly gets thousands of visitors, you don't need to click any buttons or upgrade your plan. The network scales upward instantly to meet the demand without you writing a single line of configuration code.
The pricing is also very beginner-friendly. The free tier allows for 100,000 requests per day, which is more than enough for most side projects, portfolios, or experimental tools.
What can you actually build with Workers?
You can use Workers for much more than just hosting a simple text page. Many developers use them to build an API (Application Programming Interface), which is a way for different software programs to talk to each other and exchange data.
Another common use is "URL Rewriting," where you change the destination of a link based on the user's location or device type. For example, you could send mobile users to a different version of your site automatically.
We've found that Workers are particularly effective for adding security headers to existing websites. You can intercept a request and add extra layers of protection before the user even sees the page.
What do you need to get started?
Before writing your first Worker, you should have a few basic tools ready on your computer. Don't worry if you haven't used these before; they are standard tools for modern web development.
What You’ll Need:
- Node.js (version 20.0 or higher): This is a runtime environment that lets you run JavaScript code outside of a web browser. You can download it at nodejs.org.
- npm (Node Package Manager): This comes automatically with Node.js and helps you install developer tools.
- A Cloudflare Account: You can sign up for free at dash.cloudflare.com.
- A Text Editor: We recommend Visual Studio Code, but any code editor will work.
Step 1: How do you install the Wrangler CLI?
The first step is to install Wrangler, which is a CLI (Command Line Interface—a tool used by typing text commands into a terminal). Wrangler allows you to create, preview, and publish your code directly from your computer.
Open your terminal (Command Prompt on Windows or Terminal on Mac) and type the following command:
# This installs the wrangler tool globally on your computer
npm install -g wrangler
After the installation finishes, verify it worked by typing wrangler --version. You should see a version number appear. If you see an error, try restarting your terminal window to refresh the settings.
Step 2: How do you create your first project?
Once Wrangler is installed, you can create a new project folder with a single command. This sets up a "Hello World" template so you don't have to start from a blank file.
Run this command in your terminal:
# This starts the setup wizard for a new project
npx wrangler init my-first-worker
The wizard will ask you a few questions. For a beginner, select "Hello World" script and choose "JavaScript" as the language. When it asks if you want to use Git for version control, you can select "No" for now to keep things simple.
What you should see: A new folder named my-first-worker will appear on your computer containing a file named src/index.js.
Step 3: How do you write the code?
Open the src/index.js file in your text editor. You will see some boilerplate code (standard code used as a starting point). Let's look at a simple version of what a Worker looks like:
export default {
// The 'fetch' function runs every time someone visits your URL
async fetch(request, env, ctx) {
// We create a new Response object with a friendly message
return new Response("Hello! You just built your first Cloudflare Worker.");
},
};
In this code, the request parameter contains information about the person visiting your site, like their IP address or what browser they are using. The return new Response line is what sends the message back to their screen.
Step 4: How do you test your Worker locally?
You don't have to publish your code to the internet just to see if it works. You can run a local "development server" that mimics the Cloudflare environment on your own machine.
Type this into your terminal inside your project folder:
# This runs your worker on your own computer for testing
npx wrangler dev
The terminal will provide a link, usually http://localhost:8787. Open that link in your web browser. You should see your "Hello!" message displayed on the page. It's normal to feel a bit of excitement when you see your code working for the first time!
Step 5: How do you deploy to the global network?
Once you are happy with your code, it’s time to send it to Cloudflare's servers. This process is called "deployment."
Run the following command:
# This uploads your code to Cloudflare's global network
npx wrangler deploy
If this is your first time, Wrangler will open a browser window and ask you to log in to your Cloudflare account. Once you click "Authorize," the terminal will finish uploading your code.
What you should see: The terminal will print a unique URL ending in .workers.dev. You can send this link to anyone in the world, and they will be able to see your live project.
What are some common beginner mistakes?
It is very common to run into small issues when you are starting out. Don't worry if things don't work perfectly on the first try.
One frequent mistake is forgetting to use the async keyword before the fetch function. Because Cloudflare Workers often wait for data from other websites, they use "Asynchronous Programming" (a way for code to wait for tasks to finish without freezing). If you leave out async, your code might crash when trying to handle data.
Another "gotcha" is the 1MB file size limit on the free plan. While 1MB sounds small, it is actually huge for code. Most Workers are only about 5KB to 10KB. If you hit this limit, it usually means you are trying to upload large images or videos directly in your code, which you should avoid.
Lastly, remember that Workers are "stateless." This means the Worker "forgets" everything as soon as it finishes sending a response. If you need to save data (like a user's name or a high score), you'll need to use a database like Cloudflare D1 or KV (Key-Value storage).
Next Steps
Now that you have deployed your first Worker, you can experiment with more advanced features. You might try using Claude Sonnet 4 to help you write more complex logic or explore how to connect your Worker to a frontend framework like Next.js 15.
To continue your journey, we recommend looking into "Routes," which allow you to run your Worker code on your own custom domain name instead of the default .workers.dev address.
official Cloudflare Workers documentation