0Pricing
Edge Computing with Cloudflare Workers & Deno · Lesson

Setting Up Worker Environment

Configure your local machine for Cloudflare Workers development using Wrangler CLI.

Setting Up Worker Environment is a free Edge Computing with Cloudflare Workers & Deno lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Edge Computing with Cloudflare Workers & Deno learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Get Ready for Edge Dev

Welcome! Before we build our first Cloudflare Worker, we need to set up our local development environment. This ensures you have all the tools to write, test, and deploy your code efficiently.

A proper setup makes the development process smooth and helps you quickly iterate on your edge applications.

Wrangler: Your Worker Tool

Our primary tool for interacting with Cloudflare Workers is the Wrangler CLI (Command Line Interface). It's a powerful tool that helps you:

  • Create new Worker projects
  • Develop and test Workers locally
  • Configure and deploy Workers to Cloudflare's edge
  • Manage Worker resources

Essential: Node.js & npm

Wrangler is built using Node.js, so you'll need Node.js and its package manager, npm (or yarn), installed on your machine.

  • Node.js: A JavaScript runtime environment.
  • npm: Node Package Manager, used to install libraries and tools.

If you don't have Node.js, download it from nodejs.org. We recommend using a Long Term Support (LTS) version.

Installing Wrangler CLI

Once Node.js and npm are ready, open your terminal or command prompt. We'll install Wrangler globally so it's accessible from any directory.

Run the following command:

npm install -g wrangler

Connect to Cloudflare

After installing, you need to link Wrangler to your Cloudflare account. This allows Wrangler to deploy and manage Workers on your behalf.

Execute this command and follow the browser prompts to log in:

wrangler login

Create Your First Project

Now that Wrangler is installed and authenticated, let's create a new Worker project. This command generates a basic project structure for you.

Replace my-first-worker with your desired project name:

wrangler generate my-first-worker

Understanding Project Structure

After running wrangler generate, you'll find a new directory (e.g., my-first-worker) with essential files:

  • wrangler.toml: Your Worker's configuration file.
  • src/index.js: The main JavaScript file where your Worker's logic lives.
  • package.json: Standard Node.js package file (optional, for dependencies).

Let's dive into these key files.

Configure with wrangler.toml

The wrangler.toml file is crucial. It defines your Worker's settings, like its name, type, and associated Cloudflare account.

Here's a basic example of what it might contain:

name = "my-first-worker"
main = "src/index.js"
compatibility_date = "2023-10-26"
account_id = "YOUR_CLOUDFLARE_ACCOUNT_ID"

Your Worker's Logic

The src/index.js file is where you write the JavaScript code for your Worker. Cloudflare Workers typically listen for fetch events.

This simple Worker responds with "Hello Cloudflare Workers!" to any request:

export default {
  async fetch(request, env, ctx) {
    return new Response("Hello Cloudflare Workers!");
  },
};

Test Your Worker Locally

Before deploying, you can test your Worker right on your machine! Wrangler creates a local development server that simulates the Cloudflare edge environment.

Navigate into your project directory (e.g., cd my-first-worker) and run:

wrangler dev

Wrangler Command Check

Which Wrangler command is used to connect your local environment to your Cloudflare account?

Recap: Setup Complete!

Great job! You've successfully set up your Cloudflare Workers development environment. You've learned how to:

  • Install Wrangler CLI
  • Authenticate with Cloudflare
  • Generate a new Worker project
  • Understand the basic project structure
  • Run your Worker locally using wrangler dev

You're now ready to start building powerful applications at the edge!

Frequently asked questions

Is the “Setting Up Worker Environment” lesson free?

Yes — the full text of “Setting Up Worker Environment” is free to read here on the web, and the Edge Computing with Cloudflare Workers & Deno course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Edge Computing with Cloudflare Workers & Deno course, upgrade to CoddyKit PRO.

What will I learn in “Setting Up Worker Environment”?

Configure your local machine for Cloudflare Workers development using Wrangler CLI. You practise Edge Computing with Cloudflare Workers & Deno with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Edge Computing with Cloudflare Workers & Deno?

No prior experience is required. Edge Computing with Cloudflare Workers & Deno on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Setting Up Worker Environment” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Edge Computing with Cloudflare Workers & Deno lesson?

Yes. Every Edge Computing with Cloudflare Workers & Deno lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Setting Up Worker Environment
  2. Handling HTTP Requests
  3. Deploying Your First Worker
  4. Environment Variables & Secrets in Workers
← Back to Edge Computing with Cloudflare Workers & Deno