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 CLI1. 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.
Global Installation (Recommended for Beginners)
npm install -g wrangler
# Or using yarn
yarn global add wrangler
# Or using pnpm
pnpm add -g wranglerVerify installation:
wrangler --versionProject Installation (Recommended for Production)
npm install -D wrangler3. Login / Authentication
After installation, you need to connect Wrangler to your Cloudflare account via OAuth.
wrangler loginAfter 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=falseand then copy the link to open in your local browser.
4. Common Commands
Initialize Project (init)
Create a new Workers project:
wrangler init my-workerAnswer 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:
wrangler devPress 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:
wrangler deploy