# Cloudflare Wrangler
> Build and deploy Cloudflare Workers and Pages

## Summary
Build and deploy Cloudflare Workers, Pages, and developer services. Develop locally with a full edge runtime, manage KV/R2/D1 storage, and deploy serverless functions to Cloudflare's global network.

## Capabilities
- Create and deploy Cloudflare Workers (serverless edge functions)
- Deploy static sites and full-stack apps to Cloudflare Pages
- Local development with Miniflare, a full Workers runtime simulator
- Manage KV namespaces, R2 buckets, and D1 SQLite databases
- Tail real-time logs from deployed Workers
- Manage secrets and environment variables

## When to Use
- Building and deploying serverless functions on Cloudflare's edge
- Deploying static sites or full-stack apps to Cloudflare Pages
- Need edge-first computing with low latency globally
- Working with Cloudflare storage services (KV, R2, D1)

## When NOT to Use
- Need long-running server processes (Workers have execution time limits)
- Locked into another cloud provider's ecosystem
- Applications requiring traditional server infrastructure

## Key Flags
- `dev`: Start a local development server with the Workers runtime
- `deploy`: Deploy the Worker or Pages project to Cloudflare
- `tail`: Stream real-time logs from a deployed Worker
- `kv:key put`: Write a key-value pair to a KV namespace
- `r2 object put`: Upload an object to an R2 bucket
- `d1 execute`: Execute SQL against a D1 database

## Usage Patterns
### Start local development
```
wrangler dev
```
Runs the Worker locally with hot-reloading and the full Workers API

### Deploy a Worker
```
wrangler deploy
```
Publishes the Worker to Cloudflare's global edge network

### Tail production logs
```
wrangler tail --format pretty
```
Streams real-time request and console logs from the deployed Worker

### Create a KV namespace
```
wrangler kv:namespace create MY_KV
```
Creates a new KV namespace and outputs the binding for wrangler.toml

## Input / Output
- **stdin**: Values for KV/R2 writes can be piped from stdin
- **stdout**: Deployment URLs, logs, and resource information

## Installation
- **npm**: `npm i -g wrangler`

## Related Tools
- [vercel](/tools/vercel) (alternative): Vercel for Next.js and frontend; Wrangler for Cloudflare's edge platform
- [netlify-cli](/tools/netlify-cli) (alternative): Netlify for Jamstack; Wrangler for Cloudflare Workers and Pages
- [flyctl](/tools/flyctl) (alternative): flyctl for containerized apps; Wrangler for serverless edge functions

---
Source: https://littlescripts.sh/tools/wrangler
