First Worker
import { Render, PackageManagers, DashButton } from "~/components";
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, refer to Create account.
Via the Cloudflare dashboard
Via C3 and Wrangler
Prerequisites
Create and deploy your first Worker
To create your Worker project, run:
<PackageManagers type="create" pkg="cloudflare@latest" args={"first-worker"} />
This will prompt you to install the create-cloudflare package, and lead you through setup.
<Render file="c3-post-run-steps-hello-world" product="workers" params={{ type: "Worker only", lang: "JavaScript", }} />
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.devsubdomain. -
If you choose not to deploy, go to the newly created project directory to begin writing code. Deploy your project by running the
wrangler deploycommand.
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.jsonc: 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 tonpmdocumentation onpackage-lock.json.node_modules: Refer tonpmdocumentationnode_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.
Related resources
- Get started guide - Create a new Worker with Cloudflare Workers' Get started guide.
谢谢你的反馈!