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.
To create your first Worker using the Cloudflare dashboard:
- Log in to the Cloudflare dashboard ↗ and select your account.
- Select Workers & Pages > Create application.
- Select Create Worker > Deploy.
- Sign up for a Cloudflare account ↗.
- Install
npm
↗. - Install
Node.js
↗.
Node.js version manager
Use a Node version manager like Volta ↗ or nvm ↗ to avoid permission issues and change Node.js versions. Wrangler, discussed later in this guide, requires a Node version of 16.17.0
or later.
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:
This will prompt you to install the create-cloudflare
↗ package, and lead you through setup.
For setup, select the following options:
- For What would you like to start with?, choose
Hello World example
. - For Which template would you like to use?, choose
Hello World Worker
. - For Which language do you want to use?, choose
JavaScript
. - For Do you want to use git for version control?, choose
Yes
. - For Do you want to deploy your application?, choose
No
(we will be making some changes before deploying).
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:
wrangler.toml
: Your Wrangler configuration file.index.js
(in/src
): A minimal'Hello World!'
Worker written in ES module syntax.package.json
: A minimal Node dependencies configuration file.package-lock.json
: Refer tonpm
documentation onpackage-lock.json
↗.node_modules
: Refer tonpm
documentationnode_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.
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.