Workers
Serverless at the edge
Run serverless functions at the edge using the Cloudflare Workers runtime. Write familiar JavaScript/TypeScript code that executes close to your users for minimal latency.
Worker Code Example
Requests Today
1,284,392
+12% from yesterday
Avg Latency
12ms
P95: 45ms
Error Rate
0.02%
3 errors today
Worker Code
Example API worker running at the edge
api/hello.ts
// api/hello.ts
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
if (url.pathname === "/api/users") {
const users = await env.DB.prepare(
"SELECT id, name, email FROM users LIMIT 10"
).all();
return Response.json({ users: users.results });
}
return Response.json({
message: "Hello from the edge!",
timestamp: new Date().toISOString()
});
}
}Key Features
Global Edge Network
Your code runs in data centers worldwide, close to your users.
Cold Start Free
V8 isolates eliminate cold starts for consistently fast response times.
Scale to Zero
Pay only for what you use - no idle server costs.
Standard APIs
Use familiar Web APIs like fetch, Request, Response, and more.
Worker Example
Create API endpoints with the familiar Cloudflare Workers syntax.
src/index.ts
export default {
async fetch(request) {
const url = new URL(request.url);
if (url.pathname === "/api/hello") {
return Response.json({
message: "Hello from the edge!",
});
}
return new Response("Not Found", { status: 404 });
},
};