Cloudflare Docs
Learning Paths
Edit this page
Give us feedback
Set theme to dark (⇧+D)

First Worker

  3 min read

​​ Build and deploy your first Worker

You can deploy your first Worker via the Cloudflare dashboard or programmatically using your terminal.

You must have a Cloudflare account to create a Worker. To get started with Cloudflare and create an account, refer to Get started with Cloudflare.

​​ Via the Cloudflare dashboard

To create your first Worker using the Cloudflare dashboard:

  1. Log in to the Cloudflare dashboard and select your account.
  2. Select Workers & Pages > Create application.
  3. Select Create Worker > Deploy.

​​ Via C3 and Wrangler

​​ Prerequisites

  1. Sign up for a Cloudflare account.
  2. Install npm.
  3. Install Node.js.

​​ Create and deploy your first Worker

C3 (create-cloudflare-cli) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.

To create your Worker project, run:

$ npm create cloudflare@latest
$ yarn create cloudflare

This will prompt you to install the create-cloudflare package, and lead you through setup.

To set up a basic Worker:

  1. Name your new Worker directory by specifying where you want to create your application.
  2. Select "Hello World" Worker as the type of application you want to create.
  3. Answer yes or no to using TypeScript.

You will be asked if you would like to deploy the project to Cloudflare.

  • If you choose to deploy, you will be asked to authenticate (if not logged in already), and your project will be deployed to the Cloudflare global network and available on your custom workers.dev subdomain.

  • If you choose not to deploy, go to the newly created project directory to begin writing code. Deploy your project by running the wrangler deploy command.

Refer to How to run Wrangler commands to learn how to run Wrangler commands according to your package manager.

In your Worker project directory, C3 has generated the following:

  1. wrangler.toml: Your Wrangler configuration file.
  2. index.js (in /src): A minimal 'Hello World!' Worker written in ES module syntax.
  3. package.json: A minimal Node dependencies configuration file.
  4. package-lock.json: Refer to npm documentation on package-lock.json.
  5. node_modules: Refer to npm documentation node_modules.

To continue building your Worker, open the index.js file to write your code. Refer to Examples to use ready-made code you can experiment with.

​​ Summary

You have learned how to:

  • Create and deploy a Worker project using the Cloudflare dashboard and programmatically, using your terminal.

In the next section, you can follow a video tutorial to create your first Cloudflare Workers application.

  • Get started guide - Create a new Worker with Cloudflare Workers’ Get started guide.