svg

Menu

Illustration of Cloudflare Wrangler CLI logo with terminal commands

Mastering Cloudflare Infrastructure with Wrangler CLI

MAR 23, 20263 MIN READBLOG POST

Master Cloudflare D1, Workers, Pages, and Queues with Wrangler. A complete guide to managing your edge-native CRUD operations from the command line.

This guide focuses on the CLI commands you need to Create, Read (List), Update, and Delete your Cloudflare resources directly from your terminal using wrangler.

Before managing your infrastructure, ensure you have the Wrangler CLI installed globally on your system.

Terminal window
# Install Wrangler globally
npm install -g wrangler
# Login to your Cloudflare account
wrangler login

Cloudflare D1 (SQL Database)

Terminal window
# Create a new database
wrangler d1 create <db-name>
# List all databases
wrangler d1 list
# Execute a direct SQL query
wrangler d1 execute <db-name> --command "SELECT * FROM users;"
# Apply migrations to production
wrangler d1 migrations apply <db-name> --remote
# Delete a database
wrangler d1 delete <db-name>

Cloudflare Workers (Serverless Functions)

Terminal window
# Initialize a new project
wrangler init <project-name>
# List all deployed workers
wrangler list
# Deploy your worker to the edge
wrangler deploy
# Tail live logs for debugging
wrangler tail <worker-name>
# Delete a worker (run inside project directory)
wrangler delete

Cloudflare Pages (Hosting)

Terminal window
# Create a new Pages project
wrangler pages project create <project-name>
# List all Pages projects
wrangler pages project list
# Deploy a static directory to Pages
wrangler pages deploy <directory-name>
# View live deployment logs
wrangler pages deployment tail
# Delete a Pages project
wrangler pages project delete <project-name>

Cloudflare Queues (Message Broker)

Terminal window
# Create a new queue
wrangler queues create <queue-name>
# List all active queues
wrangler queues list
# Attach a worker as a consumer
wrangler queues consumer add <queue-name> <worker-name>
# Remove a consumer from a queue
wrangler queues consumer remove <queue-name> <worker-name>
# Delete a queue
wrangler queues delete <queue-name>

Cloudflare KV (Key-Value Store)

Terminal window
# Create a new KV namespace
wrangler kv:namespace create <namespace-name>
# List all KV namespaces
wrangler kv:namespace list
# Put a value into KV
wrangler kv:key put --binding=<BINDING> "my-key" "my-value"
# Delete a KV namespace
wrangler kv:namespace delete --binding=<BINDING>

Cloudflare Workers: Secrets & Variables

Terminal window
# Set a secret (interactive prompt will ask for value)
wrangler secret put <SECRET_NAME>
# List only the names of set secrets
wrangler secret list
# Delete a secret
wrangler secret delete <SECRET_NAME>
# Use environment variables (non-sensitive) locally
# Define these in a .dev.vars file or wrangler.json [vars]
wrangler dev
# Deploy local variables/config to production
wrangler deploy
# Bulk upload secrets from a file (advanced)
wrangler secret bulk <file-path.json>

Let’s build your next edge‑native project

Message me if you want a fast, scalable, and privacy‑first product I can ship in 1/2 weeks.

decorative star