Skip to content

Cloudflare Wrangler CLI User Guide

Wrangler is the official command-line interface (CLI) tool for Cloudflare Workers and CI/CD processes. With Wrangler, you can construct, test Cloudflare Workers properly on your local machine, and deploy them to Cloudflare's global network. It also supports command-line management for Cloudflare Pages.

Wrangler CLI

1. Prerequisites

Before using Wrangler, please ensure your system has Node.js and npm (or pnpm/yarn) installed.

Compatibility Hint

It is recommended to use the latest LTS version of Node.js for best compatibility.

2. Install Wrangler

You can install Wrangler globally or as a development dependency for your project.

bash
npm install -g wrangler
# Or using yarn
yarn global add wrangler
# Or using pnpm
pnpm add -g wrangler

Verify installation:

bash
wrangler --version
bash
npm install -D wrangler

3. Login / Authentication

After installation, you need to connect Wrangler to your Cloudflare account via OAuth.

bash
wrangler login

After running this command, the browser will automatically pop up the Cloudflare authorization page. Click "Allow" to complete authorization.

  • If you are on a non-GUI interface (like a Linux server), you can use wrangler login --browser=false and then copy the link to open in your local browser.

4. Common Commands

Initialize Project (init)

Create a new Workers project:

bash
wrangler init my-worker

Answer a few questions according to the prompts (whether to use TypeScript, whether to create wrangler.toml, etc.), and Wrangler will automatically generate the project template for you.

Local Development (dev)

Start the development server locally to simulate the Cloudflare Edge environment:

bash
wrangler dev

Press b to open in the browser, press x to exit. Local development is very fast and supports hot updates.

Deploy (deploy)

Publish your code to the Cloudflare global network:

bash
wrangler deploy

All resources are from the open-source community. Disclaimer