⚠️ This lesson is retired and might contain outdated information.

Set Up Cloudflare Workers Locally with Cloudflare Wrangler

Obinna Ekwuno
InstructorObinna Ekwuno
Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 2 years ago

In this lesson, you will install and set up Cloudflare Wrangler and use it to generate a new worker.

Instructor: [0:00] To set up Cloudflare Workers on your computer, you go to your terminal and run npm install -g cloudflare@workers. You can also do this with yarn and after you've installed, you can run wrangler login in order to connect your CLI with your dashboard.

[0:22] You can also run wrangler whoami in order to get your account ID, which you connect your projects to your dashboard, so that when you run wrangler publish, you'll be able to see your Cloudflare Worker, your dashboard.

[0:40] You use the wrangler generate command in order to set up a new worker. What comes after the generate command will be the name of the folder and the name of your projects. In this case, we will say, wrangler generate airtable-function. This will be the name of our project, and will also be the name of our Worker.

[1:09] If we head over to the folder, you can see that a bunch of files have been automatically created. In the wrangler.toml file, you can see the space where you would input your account ID. To get this, first change directory into the folder that Wrangler has created for your Worker's function, in our case, it would be airtable-function, and run, wrangler whoami.

[1:42] This should automatically pop up your account ID if you are logged in from your CLI. If you open up the index.js file, you can see the default templates of your Worker function. The Worker function has an addListenerEvents that performs a FETCH, and responds with another function. This function can be found below as handleRequest. This returns, Hello Worker, to the screen.

[2:11] To run this function, we can run this Worker with the wrangler dev command. If you click Enter, you can see that our Worker is available on local hosts, and it shows, Hello Worker.

egghead
egghead
~ 4 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