Cloudflare Workers let you run JavaScript (or TypeScript, Rust via WASM, and more) at the edge — inside Cloudflare’s global network, close to your users. There’s no server to manage, no cold-start penalty, and your code runs in ~300 locations worldwide by default.
This guide walks through everything you need to ship your first Worker.
Prerequisites
- A free Cloudflare account
- Node.js 18+ installed locally
1. Install Wrangler
Wrangler is the official Cloudflare CLI. It handles local development, deployment, secret management, and more.
npm install -g wrangler
wrangler login
The wrangler login command opens a browser window to authenticate with your Cloudflare account.
2. Create a new Worker project
npm create cloudflare@latest my-worker
cd my-worker
You’ll be prompted to choose a template. Pick “Hello World” Worker to start simple.
This creates a project with:
my-worker/
├── src/
│ └── index.ts ← your Worker code
├── wrangler.jsonc ← project config
└── package.json
3. Write your first Worker
Open src/index.ts. The default looks like this:
export default {
async fetch(request: Request): Promise<Response> {
return new Response('Hello, World!');
},
};
Every Worker exports a default object with a fetch handler. It receives a standard
Request and must return a
Response. That’s it — no
framework required.
Let’s make it slightly more interesting:
export default {
async fetch(request: Request): Promise<Response> {
const url = new URL(request.url);
const name = url.searchParams.get('name') ?? 'World';
return new Response(`Hello, ${name}!`, {
headers: { 'content-type': 'text/plain' },
});
},
};
4. Run it locally
npm run dev
Wrangler starts a local dev server at http://localhost:8787. Try:
curl "http://localhost:8787?name=Cloudflare"
# → Hello, Cloudflare!
Local dev uses Miniflare under the hood — a full Workers runtime simulator that supports KV, Durable Objects, R2, and most other bindings.
5. Deploy
npm run deploy
That’s it. Wrangler builds your Worker, uploads it to Cloudflare, and gives you a URL like
https://my-worker.your-subdomain.workers.dev.
Your Worker is now running in 300+ cities worldwide. Every request is handled by the location closest to the user.
What’s next?
- Add KV storage — persist key-value data globally
- Use D1 — SQLite at the edge
- Schedule with Cron Triggers — run Workers on a schedule
- Explore the full Workers API — the official docs
Workers have a generous free tier: 100,000 requests/day, with no cold starts, ever.