Wrangler CLI Guide
Wrangler is the official CLI tool for managing Cloudflare Workers, Pages, R2, D1, and other Cloudflare resources. For Azure developers, it is the equivalent of Azure Functions Core Tools (func) combined with Azure CLI (az).
Comparison with Azure Tools
| Operation | Azure | Cloudflare |
|---|---|---|
| Local dev server | func start | wrangler dev |
| Deploy to production | func azure functionapp publish | wrangler deploy |
| Live log streaming | func azure functionapp logstream | wrangler tail |
| Set secrets | az functionapp config appsettings set | wrangler secret put |
| List resources | az resource list | wrangler whoami / sub-commands |
| Config file | local.settings.json | wrangler.toml / wrangler.jsonc |
Installation
npm install -g wrangler
# or use npx without installing
Check version:
wrangler --version
Authentication
Login to your Cloudflare account with wrangler login. A browser window opens and completes an OAuth flow.
wrangler login
# Opens browser for Cloudflare dashboard authentication
wrangler whoami
# Shows the currently logged-in account
For CI/CD environments (GitHub Actions, etc.), pass an API token via environment variable:
export CLOUDFLARE_API_TOKEN="your-api-token"
Creating a Project
# Create a new project from a template
wrangler init my-worker
# Or use npm create cloudflare (recommended)
npm create cloudflare@latest my-worker
An interactive prompt lets you choose a template — similar to func new in Azure Functions Core Tools.
Configuration File (wrangler.toml)
wrangler.toml is the Worker configuration file, equivalent to Azure Functions' host.json + local.settings.json.
name = "my-worker"
main = "src/index.ts"
compatibility_date = "2024-11-01"
# Non-sensitive environment variables
[vars]
MY_VAR = "hello"
API_BASE_URL = "https://api.example.com"
# KV binding (equivalent to Azure Cache for Redis)
[[kv_namespaces]]
binding = "MY_KV"
id = "abc123def456"
# R2 binding (equivalent to Azure Blob Storage)
[[r2_buckets]]
binding = "MY_BUCKET"
bucket_name = "my-bucket"
# D1 binding (SQLite-based edge DB)
[[d1_databases]]
binding = "MY_DB"
database_name = "my-database"
database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# Production environment config
[env.production]
name = "my-worker-prod"
vars = { ENVIRONMENT = "production" }
Only store non-sensitive environment variables in wrangler.toml's [vars] section. API keys and other secrets should be managed with wrangler secret (see below).
Local Development
# Start local dev server with hot reload
wrangler dev
# Specify port
wrangler dev --port 8787
# Run locally but connect to real Cloudflare services
wrangler dev --remote
wrangler dev runs on miniflare (a local Cloudflare Workers runtime emulator) by default. KV, R2, and D1 are all emulated locally, so you can develop without any real cloud resources.
Add --remote to connect to actual Cloudflare resources — analogous to disabling local function emulation in Azure Functions Core Tools.
Deploying
# Deploy to default environment
wrangler deploy
# Deploy to a named environment (uses [env.production] in wrangler.toml)
wrangler deploy --env production
# Dry run (preview changes without deploying)
wrangler deploy --dry-run
After deployment, the Worker is available at https://<worker-name>.<subdomain>.workers.dev.
Secret Management
Sensitive values are stored in Cloudflare's encrypted secret store — similar in concept to Azure Key Vault references in App Service.
# Set a secret interactively (reads value from stdin)
wrangler secret put DATABASE_PASSWORD
# List secrets
wrangler secret list
# Delete a secret
wrangler secret delete DATABASE_PASSWORD
# Set a secret for a specific environment
wrangler secret put API_KEY --env production
Access secrets in Worker code as normal environment variables:
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const password = env.DATABASE_PASSWORD; // secret value
return new Response('OK');
},
};
Log Streaming (tail)
Stream real-time logs from a deployed Worker — equivalent to Azure Functions' logstream.
# Stream real-time logs
wrangler tail
# Tail a specific environment
wrangler tail --env production
# Filter by status code
wrangler tail --status error
# Output as JSON
wrangler tail --format json
KV (Key-Value Store) Operations
Cloudflare Workers KV is the edge equivalent of Azure Cache for Redis (or Azure Table Storage).
# Create a KV Namespace
wrangler kv namespace create MY_KV
# List all namespaces
wrangler kv namespace list
# Put a key-value pair
wrangler kv key put --namespace-id <id> my-key "my-value"
# Get a value
wrangler kv key get --namespace-id <id> my-key
# List all keys
wrangler kv key list --namespace-id <id>
# Delete a key
wrangler kv key delete --namespace-id <id> my-key
# Bulk import from file
wrangler kv bulk put --namespace-id <id> data.json
R2 (Object Storage) Operations
R2 is the equivalent of Azure Blob Storage, but with no egress fees.
# Create a bucket
wrangler r2 bucket create my-bucket
# List buckets
wrangler r2 bucket list
# Upload a file
wrangler r2 object put my-bucket/path/to/file.txt --file ./local-file.txt
# Download a file
wrangler r2 object get my-bucket/path/to/file.txt --file ./output.txt
# Delete an object
wrangler r2 object delete my-bucket/path/to/file.txt
# Delete a bucket
wrangler r2 bucket delete my-bucket
D1 (SQLite Edge DB) Operations
D1 is Cloudflare's edge SQLite database — think of it as a lightweight edge version of Azure SQL Database.
# Create a database
wrangler d1 create my-database
# List databases
wrangler d1 list
# Run SQL directly (locally)
wrangler d1 execute my-database --local --command "SELECT * FROM users"
# Run a SQL migration file
wrangler d1 execute my-database --file ./migrations/0001_init.sql
# Run against the production database
wrangler d1 execute my-database --command "SELECT COUNT(*) FROM users"
# Export (backup)
wrangler d1 export my-database --output ./backup.sql
Pages (Static Sites) Operations
Cloudflare Pages is the equivalent of Azure Static Web Apps.
# Create a Pages project
wrangler pages project create my-site
# Deploy build output
wrangler pages deploy ./dist --project-name my-site
# List deployments
wrangler pages deployment list --project-name my-site
# List projects
wrangler pages project list
Automated Deployment with GitHub Actions
name: Deploy Worker
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy to Cloudflare Workers
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
command: deploy --env production
For Azure DevOps, run Wrangler via npx:
- task: Bash@3
displayName: Deploy Cloudflare Worker
env:
CLOUDFLARE_API_TOKEN: $(CLOUDFLARE_API_TOKEN)
inputs:
script: npx wrangler deploy --env production
Quick Reference
# Auth & account
wrangler login # Log in to Cloudflare
wrangler logout # Log out
wrangler whoami # Show current account
# Workers
wrangler dev # Start local dev server
wrangler deploy # Deploy Worker
wrangler tail # Stream live logs
wrangler delete # Delete Worker
# Secrets
wrangler secret put <name> # Set a secret
wrangler secret list # List secrets
wrangler secret delete <name> # Delete a secret
# KV
wrangler kv namespace list # List namespaces
wrangler kv key put ... # Set a key
wrangler kv key get ... # Get a value
# R2
wrangler r2 bucket list # List buckets
wrangler r2 object put ... # Upload a file
# D1
wrangler d1 list # List databases
wrangler d1 execute ... # Run SQL
# Pages
wrangler pages deploy ./dist # Deploy Pages site
Summary: Core Tools vs Wrangler
| Feature | Azure Functions Core Tools | Wrangler |
|---|---|---|
| Local execution | func start | wrangler dev |
| Deploy | func azure functionapp publish | wrangler deploy |
| Live logs | func azure functionapp logstream | wrangler tail |
| Set env vars | az functionapp config appsettings set | wrangler secret put |
| New project | func init / func new | npm create cloudflare |
| Runtime emulation | Azurite + local runtime | miniflare (bundled in Wrangler) |
| Config file | host.json + local.settings.json | wrangler.toml |
| CI/CD action | azure/functions-action | cloudflare/wrangler-action |