Create a New Cloudflare Workers Project with Wrangler

Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

Creating a new workers project using Wrangler is pretty easy. We first will install and double-check that we have Wrangler installed. Then we will connect Wrangler to our cloudflare project. Lastly, using the terminal, we can easily create our new Wrangler project.

Instructor: [0:00] Let's begin by installing Cloudflare CLI, Wrangler. To do that, I'll run npm install -g for a global install, and then the package name, cloudflare/wrangler. You can check that you have Wrangler installed by running wrangler --version. Right now, I'm at Wrangler 1.19.3, though any version of Wrangler will work.

[0:21] Next, we'll connect Wrangler to our Cloudflare account. To do that, I'll run Wrangler login. Wrangler will ask if it's OK to open a page in my browser, I'll say y for yes. In the browser, you'll see this authorization page that says, "Allow Wrangler to make changes to your Cloudflare account." You can see all the different permissions it's going to ask for, and I'll just say, "Allow."

[0:43] Now, I look at this page, "You have granted authorization to Wrangler. Welcome to serverless execution environment," etc. We're now logged in. Feel free to close this browser window. Now, back here in the console, you can see it says, "Successfully configured. You can find your config file at this path." We know that we're now authorized.

[1:00] Next, let's create a new project which is what we're going to be using to learn more about Workers KV. To do that, I'll run Wrangler Generate and then I'll give it a project name like My KV Project.

[1:13] Wrangler will create a new project in the folder, My KV Project. Now let's open that up and take a look. You can see that we've created this new project here with all of these files. The ones you need to know are name, which is My KV Project.

[1:25] This is going to be the name that your project is deployed to when it's deployed to Cloudflare wWorkers. Type, which is just JavaScript. You can customize this to make use of some different build systems, or you can provide your own.

[1:36] Then account ID and workers dev, route, Zone ID, all relate to how and where you deploy your application. If you want to deploy to a custom domain, or you want to deploy between different accounts, you can do all of that here.

[1:49] Finally, compatibility date is a tool you can use to opt into different features in the Wranglers runtime, for instance, bug fixes and patches, and stuff like that. Though for now we're just going to leave all of this as is. We don't need to configure anything extra at the moment.

[2:03] Index.js is our source code, which we'll be filling in with more functionality. Though for now you just need to look at the basics here and see that we have this fetch event coming in.

[2:13] It responds to that fetch event using this handle requests function, which just returns a new response with the text, "Hello Worker." This is just a content type of text plain. It's literally just plain text being returned back to the client, though we'll customize this more.

[2:29] If you want to learn more about how that works, check out my, "Getting Started with Cloudflare Workers" course.

egghead
egghead
~ 9 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today