Commands

Execute Cloudflare CLI commands and automate Cloudflare workflows

What Is This?

Overview

Cloudflare provides a powerful command-line interface through its Wrangler tool, enabling developers to manage Workers, Pages, KV storage, R2 buckets, and other Cloudflare services directly from the terminal. Rather than navigating the Cloudflare dashboard for every configuration change or deployment, developers can script, automate, and integrate these operations into their existing workflows with precision and speed.

The Wrangler CLI serves as the primary interface for interacting with Cloudflare's developer platform. It supports the full lifecycle of serverless application development, from initializing a new project and running a local development server to deploying production-ready code and managing environment variables. Understanding the available commands and their options significantly reduces the time spent on repetitive tasks.

Cloudflare's CLI tooling integrates naturally with modern JavaScript and TypeScript ecosystems. Projects built with frameworks like Next.js, Remix, or plain Workers can be managed through a consistent set of commands, making it easier to maintain multiple projects under a unified workflow.

Who Should Use This

  • Backend and full-stack developers building serverless applications on Cloudflare Workers
  • DevOps engineers automating deployment pipelines for Cloudflare-hosted services
  • Frontend developers deploying static sites and server-side rendered applications through Cloudflare Pages
  • Platform engineers managing KV namespaces, R2 buckets, and Durable Objects at scale
  • Teams adopting infrastructure-as-code practices who need repeatable, scriptable deployment commands
  • Developers migrating existing applications to Cloudflare's edge network

Why Use It?

Problems It Solves

  • Manual dashboard operations are slow and error-prone when deploying frequently or managing multiple environments
  • Inconsistent deployments caused by clicking through UI steps can be eliminated by scripting Wrangler commands in CI/CD pipelines
  • Local testing without proper tooling leads to bugs discovered only in production, which Wrangler's local dev server addresses directly
  • Managing secrets and environment variables through a UI is impractical for teams, and Wrangler provides secure CLI-based secret management
  • Coordinating multiple Cloudflare resources such as Workers, bindings, and storage requires a unified tool rather than separate dashboard sections

Core Highlights

  • Initialize new Worker projects with preconfigured templates using a single command
  • Run a local development server that closely mirrors the Cloudflare edge runtime
  • Deploy Workers and Pages projects to production or staging environments
  • Manage KV namespaces and write, read, or delete key-value pairs from the terminal
  • Upload and manage files in R2 object storage buckets
  • Handle secrets securely without exposing values in configuration files
  • Tail live logs from deployed Workers for real-time debugging
  • Generate TypeScript types from your Wrangler configuration automatically

How to Use It?

Basic Usage

Install Wrangler globally or use it through npx:

npm install -g wrangler
wrangler --version

Authenticate with your Cloudflare account:

wrangler login

Initialize a new Worker project:

wrangler init my-worker

Deploy a Worker to production:

wrangler deploy

Specific Scenarios

Local Development with Live Reload

Start a local development server that watches for file changes and reloads automatically:

wrangler dev --local

Managing KV Storage

Create a KV namespace and write a value:

wrangler kv namespace create MY_NAMESPACE
wrangler kv key put --namespace-id=<id> "user:123" '{"name":"Alice"}'

Handling Secrets

Add a secret to a deployed Worker without storing it in plain text:

wrangler secret put API_KEY

Real-World Examples

A deployment script in a CI pipeline might run wrangler deploy --env production after tests pass, ensuring only verified code reaches the edge. A developer debugging a live issue can run wrangler tail to stream request logs directly to the terminal. A team managing multiple environments can use wrangler deploy --env staging to push changes to a staging Worker before promoting to production.

When to Use It?

Use Cases

  • Deploying serverless functions to Cloudflare's global edge network
  • Automating deployments in GitHub Actions or other CI/CD systems
  • Debugging production Workers using live log tailing
  • Seeding or querying KV and R2 storage during development
  • Managing multiple deployment environments with environment-specific configurations
  • Rotating secrets and API keys without modifying source code
  • Generating type definitions for Worker bindings in TypeScript projects

Important Notes

Requirements

  • Node.js version 16.17.0 or higher must be installed on the local machine
  • A Cloudflare account with appropriate permissions for the resources being managed
  • Authentication via wrangler login or a valid CLOUDFLARE_API_TOKEN environment variable for CI environments