Create your first Cloudflare Worker
import { Steps } from ‘@astrojs/starlight/components’;
In this tutorial, we’ll create a Cloudflare Worker, serve it locally, and deploy it to Cloudflare — all from an Nx workspace.
Before you start
Section titled “Before you start”- Node.js 22 or later — an active LTS release (Node 24 is the latest). Required by Nx and Wrangler.
- A Cloudflare account — needed for deployment. Sign up at dash.cloudflare.com.
- Wrangler v4 — installed automatically when we add the plugin.
Compatibility
Section titled “Compatibility”| Nx version | Plugin version |
|---|---|
| 17.x | 1.x |
| 18.x | 2.x |
| 19.x | 3.x |
| 20.x | 4.x |
| 21.x | 5.x |
| 22–23.x | 6.x |
Wrangler v4 is a peer dependency. The init generator installs it
automatically; if you add the plugin manually, install it with
bun add -D wrangler.
-
Add the plugin to our workspace
We’ll use
nx add, which installs the package and runs theinitgenerator to set up workspace-level dependencies and register the inference plugin innx.json:bunx nx add @naxodev/nx-cloudflareThis installs Wrangler v4,
@cloudflare/workers-types, and Vitest as devDependencies, and adds@naxodev/nx-cloudflare/pluginto thepluginsarray innx.jsonso Worker targets are inferred automatically. -
Generate a Worker
We’ll scaffold a hello-world Worker using the application generator, which wraps Cloudflare’s create-cloudflare (C3) CLI and makes the result Nx-ready:
bunx nx g @naxodev/nx-cloudflare:application my-worker --type=hello-worldThe generator creates a
my-worker/directory with awrangler.jsoncconfig, asrc/index.tsentry point, and apackage.jsonthat registers the project with Nx. It also retargets the Wrangler$schemato the workspace root and strips redundant package scripts. -
Serve the Worker locally
Now we can run the Worker in a local dev server:
bunx nx serve my-workerThis runs
wrangler devfrom the project root. The server is ready when Wrangler printsReady on http://localhost:8787. Open that URL to see the Worker’s response. -
Deploy to Cloudflare
When we’re ready to deploy, we run:
bunx nx deploy my-workerThis runs
wrangler deploy, which uploads the Worker to Cloudflare’s edge network. On first deploy, Wrangler opens a browser to authenticate with your Cloudflare account. Pass Wrangler flags through after--:bunx nx deploy my-worker -- --dry-runThe
--dry-runflag validates the deployment without publishing.
Verify
Section titled “Verify”Confirm the inferred targets resolved correctly:
bunx nx show project my-worker
This lists serve, deploy, typegen, version-upload, and tail,
confirming the plugin registered the project.
To verify the deployment, visit the Worker’s URL. Wrangler prints the URL on
successful deploy (e.g. https://my-worker.<subdomain>.workers.dev).
Next steps
Section titled “Next steps”- Application generator reference — all scaffolding options (templates, frameworks, languages)
- Inferred targets reference —
serve,deploy,typegen,version-upload,tail - How Wrangler config inference works — why the plugin reads your Wrangler config
- Plugin options — customizing inferred target names