Cloudflare Workers run your code on Cloudflare’s global network. The Wrangler CLI is the main tool to develop, test, and deploy them from your terminal.
npm, pnpm, or yarnInstall Wrangler globally or as a dev dependency in your project:
npm install -D wrangler
Or with pnpm / yarn if you prefer. You can also use npx wrangler without a global install.
Log in once so Wrangler can talk to your account:
npx wrangler login
This opens a browser flow to authorize the CLI.
Scaffold a minimal Worker:
npx wrangler init my-worker
cd my-worker
Pick the starter you want (e.g. “Hello World” JavaScript or TypeScript). You’ll get an entry file (often src/index.ts or src/index.js) and a config file.
wrangler.toml or wrangler.jsonWrangler reads wrangler.toml (or wrangler.json / wrangler.jsonc in newer setups). At minimum you usually set:
name – Worker name in the dashboardmain – path to your entry modulecompatibility_date – Workers runtime compatibility (use a recent date from the docs)Example wrangler.toml:
name = "my-worker"
main = "src/index.ts"
compatibility_date = "2025-01-01"
[vars]
ENVIRONMENT = "production"
Use [vars] for non-secret configuration. For API keys and tokens, use secrets (below), not plain vars in the repo.
Start the dev server with hot reload:
npx wrangler dev
By default this binds to a local URL and proxies requests through the Workers runtime so behavior is close to production. You can pass --remote to run against Cloudflare’s edge while still developing (useful for some bindings).
When you’re ready to publish:
npx wrangler deploy
Wrangler uploads your bundle and updates the Worker. The command output includes your Worker’s *.workers.dev URL (if enabled) or confirms the route you configured.
To run on your own hostname, configure routes or workers_dev in wrangler.toml and ensure the zone is on Cloudflare. See Routes and domains in the docs.
Never commit API keys. Store them as encrypted secrets:
npx wrangler secret put MY_API_KEY
You’ll be prompted to paste the value. In code, read it from the environment your handler receives (e.g. env.MY_API_KEY in the Workers fetch handler).
List secrets (names only) in the dashboard or via Wrangler where supported.
You can define [env.staging] (and similar) blocks in wrangler.toml with different name, vars, or routes. Deploy to a specific environment:
npx wrangler deploy --env staging
Keep environment-specific secrets separate with the same secret put flow scoped to that env when needed.
| Command | Purpose |
|--------|---------|
| wrangler login | Authenticate CLI |
| wrangler dev | Local development |
| wrangler deploy | Deploy to Cloudflare |
| wrangler tail | Stream live logs from a deployed Worker |
| wrangler secret put NAME | Set a secret |
| wrangler whoami | Confirm logged-in account |
compatibility_date and bump it intentionally when you want new runtime behavior.wrangler tail right after deploy to debug production issues.wrangler deploy in GitHub Actions (or similar) with a API token stored as CLOUDFLARE_API_TOKEN—Wrangler picks it up automatically.With Wrangler installed, a small wrangler.toml, and wrangler dev / wrangler deploy, you have a fast loop from laptop to the edge.