Install and Configure the Cloudflare Workers CLI Wrangler

Share this video with your friends

Social Share Links

Send Tweet

Using NPM, you can install Cloudflare Workers' CLI (command-line interface), Wrangler, by typing npm install -g @cloudflare/wrangler into your command line. Wrangler allows you to generate and publish Cloudflare Workers projects. We'll also use the wrangler login command which will give you a link to authorize Wrangler. This will set up an API token specifically for your Wrangler installation that will allow you to publish and read all the Workers and Workers KV information that you need.

Instructor: [0:01] With my Cloudflare Workers account created, it's time to install Wrangler, the command line tool that we use to create and publish Workers projects. I'm in Visual Studio Code shell, but you can use pretty much any shell that you would like, and the only requirement is that you have npm installed.

[0:15] You can see I have npm 7. installed, and I'm using Node version 15.3. With npm installed, all I need to do is run npm install -g with the package name cloudflare/wrangler. It'll grab all the packages that I need. You can see if I run wrangler --version, it prints out Wrangler 1.12.2.

[0:40] With Wrangler installed, it's now time to authenticate my Wrangler installation with my Cloudflare workers user. To do that, I'll just run wrangler login. It'll ask if I want to open a page in my browser. I'll say Y for Yes.

[0:54] Depending on your operating system, your shell, sometimes this will open up the link. Though, in my case, it didn't, because I'm on the Windows subshell. I'll just copy this. Go back to my Workers tab. I'll paste this link in.

[1:08] You can see it will basically set up an API token specifically for my Wrangler installation that will allow me to publish and read all the Workers and Workers KV information that I need, so I'll just click Authorize wrangler. It's now authorized. If I come back to my terminal, you can see it says, "Successfully configured. You can find your configuration file at," and then there's this path here.

[1:33] The last thing that I want to do is make sure that I'm logged in with what I would expect, so I'll run wrangler whoami. You can see that it prints out, "You are logged in with an API token associated with the email," and then this is my email here, as well as my account name and my account ID, which we'll use later on to publish our first Workers project.