惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
AI
AI
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
Vercel News
Vercel News
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
WordPress大学
WordPress大学
Martin Fowler
Martin Fowler
博客园 - 【当耐特】
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
F
Full Disclosure
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
H
Help Net Security
Recorded Future
Recorded Future
N
News and Events Feed by Topic
雷峰网
雷峰网
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
aimingoo的专栏
aimingoo的专栏
S
Schneier on Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Project Zero
Project Zero
罗磊的独立博客
G
GRAHAM CLULEY
腾讯CDC
P
Privacy International News Feed
V
V2EX
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hugging Face - Blog
Hugging Face - Blog
爱范儿
爱范儿
H
Heimdal Security Blog
L
LINUX DO - 热门话题
Forbes - Security
Forbes - Security
美团技术团队
MongoDB | Blog
MongoDB | Blog
Security Latest
Security Latest
M
MIT News - Artificial intelligence
T
Tor Project blog
Cisco Talos Blog
Cisco Talos Blog
宝玉的分享
宝玉的分享
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog

Flavio Copes

Workers Cache: a cache in front of your Cloudflare Worker Cloudflare Drop: drag a folder, get a live site Temporary Cloudflare accounts: agents can now deploy without signing up Moondream 3.1 on Workers AI: fast vision at the edge inferencecost.dev: what will AI inference cost you at 10k users? Sitebase: all the features your website needs, in one place StackPlan: figure out where to deploy your app, and what it How the Cloudflare Pages build cache works The Summer of Code How I generate an Open Graph image for every post New: 90 free tools for developers How I added search to my static site with Pagefind How to rebuild a Cloudflare site on a schedule Cloudflare Email Workers: run code when an email arrives Cloudflare Turnstile: stop bots without annoying CAPTCHAs Cloudflare Workers: secrets and environments Cloudflare Workers observability: logs and traces Cloudflare Analytics Engine: store and query metrics The AI Workshop (July 2026 cohort) Cloudflare Cron Triggers: run a Worker on a schedule Cloudflare Durable Objects: state that lives in one place Cloudflare Queues: run work in the background Cloudflare R2: object storage without egress fees Cloudflare KV: a key-value store for your Workers Cloudflare D1: a SQL database for your Workers Serving a website with Cloudflare Workers static assets Wrangler: the Cloudflare Workers command line tool Executor: one gateway to connect your AI agent to every tool Vercel eve: an open framework for building AI agents Flue: the open framework for building AI agents Val Town: write and deploy code in seconds A hands-on guide to The Agency, a collection of AI agents The AI Workshop (June 2026 cohort) The AI Workshop (May 2026 cohort) The AI Workshop (Apr 2026 cohort)
Cloudflare Workers: your first serverless function
Flavio Copes · 2026-06-20 · via Flavio Copes

By Flavio Copes

What Cloudflare Workers are and how to build, run, and deploy your first one. The foundation of the whole Cloudflare developer platform.

~~~

I run a few things in production on Cloudflare, and it all starts with the same building block: a Worker.

A Worker is a small piece of JavaScript that runs on Cloudflare’s servers. There’s no server to set up, no machine to keep alive. You write a function, deploy it, and it runs.

The neat part is where it runs. Cloudflare has servers all over the world, and your Worker runs on the one closest to whoever is calling it. So it’s fast for everyone.

This is the first post in a series where I document the Cloudflare tools I actually use. Everything else, the databases, storage, queues, builds on top of Workers. So let’s start here.

What a Worker looks like

A Worker is a function that takes a request and returns a response.

export default {
  async fetch(request, env, ctx) {
    return new Response('Hello from the edge!')
  },
}

That’s a complete Worker. When someone hits its URL, the fetch function runs and returns the response.

The three arguments matter:

  • request is the incoming request, a standard Request object.
  • env holds your bindings: databases, storage, secrets. More on those in later posts.
  • ctx lets you do work after the response is sent, with ctx.waitUntil().

If you’ve used the Fetch API in the browser, this is the same Request and Response. No new framework to learn.

Create a project

The fastest way to start is the official scaffolder:

npm create cloudflare@latest my-worker

Pick the “Hello World” Worker when it asks. It sets up the project, installs wrangler (Cloudflare’s CLI), and creates a wrangler.jsonc config file.

Then move into the folder:

cd my-worker

Run it locally

You don’t deploy to test. Cloudflare runs the same engine on your machine:

npx wrangler dev

This starts a local server, usually on http://localhost:8787. Open it and you’ll see your message. Edit the code, save, and it reloads.

Read the request

Let’s do something with the request. Here we read the path and respond based on it:

export default {
  async fetch(request, env, ctx) {
    const url = new URL(request.url)

    if (url.pathname === '/') {
      return new Response('Home')
    }

    return new Response('Not found', { status: 404 })
  },
}

You can return JSON just as easily:

return Response.json({ ok: true })

Deploy it

When you’re happy, one command puts it live:

npx wrangler deploy

Wrangler uploads your Worker and gives you a URL like my-worker.your-name.workers.dev. That’s it, your code is running worldwide.

Wondering what this costs once traffic grows? I built a free Workers cost estimator that calculates it for Workers, KV, D1, R2 and Durable Objects.

The first time, it’ll ask you to log in to your Cloudflare account in the browser.

What comes next

On its own, a Worker is just a function. The power comes from bindings: you attach a database, a storage bucket, a queue, and they show up on that env argument.

That’s what the rest of this series is about. A database with D1, files with R2, key-value with KV, background jobs with Queues, and more.

But it all starts here, with a function that returns a response.

If you want to read ahead, the Workers docs are excellent.

~~~

Related posts about cloudflare: