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.