Get started with Wrangler
Wrangler is a command-line tool for building Cloudflare Workers.
Install
Installing Wrangler, the Workers CLI, allows you to init, dev, and publish your Workers projects.
To install wrangler, ensure you have npm and Node.js installed. Wrangler requires a Node version of 16.13.0 or later.
Then run:
$ npm install -g wrangler
or install with yarn:
$ yarn global add wrangler
To check your Wrangler version, run:
$ wrangler --version
Authenticate
With installation complete, Wrangler will need access to a Cloudflare OAuth token to manage Workers resources on your behalf.
Run the command wrangler login, which will automate this process.
Wrangler will attempt to automatically open your web browser to complete the login process to your Cloudflare account. If you have issues completing this step or you do not have access to a browser GUI, you can copy and paste the URL generated by wrangler login in your terminal into a browser and log in.
$ wrangler login ⛅️ wrangler 2.0.7-----------------------------------------------------Attempting to login via OAuth...Successfully logged in.If you prefer to use API tokens for authentication, such as in headless or continuous integration environments, refer to Running Wrangler in CI/CD.
Open the browser, log in to your account, and select Allow. This will send an OAuth Token to Wrangler so it can deploy your scripts to Cloudflare.
Use wrangler login on a remote machine
If you are using Wrangler from a remote machine, but run the login flow from your local browser, you will receive the following error message after logging in:This site can't be reached.
To finish the login flow, run wrangler login and go through the login flow in the browser:
$ wrangler login ⛅️ wrangler 2.1.6-------------------Attempting to login via OAuth...Opening a link in your default browser: https://dash.cloudflare.com/oauth2/auth?xyz...The browser login flow will redirect you to a localhost URL on your machine.
Leave the login flow active. Open a second terminal session. In that second terminal session, use curl or an equivalent request library on the remote machine to fetch this localhost URL. Copy and paste the localhost URL that was generated during the wrangler login flow and run:
$ curl <LOCALHOST_URL>
Update
To update Wrangler, run:
$ npm -g install wrangler@latest
Note that this command will not update Wrangler in projects where it is already installed. If you already have a package.json in your directory with Wrangler installed, run:
$ npm update wrangler --save
Related resources
With Wrangler successfully installed, refer to Commands and Configuration to continue building with Wrangler.