Skip to content

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.

  • 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.
Nx versionPlugin version
17.x1.x
18.x2.x
19.x3.x
20.x4.x
21.x5.x
22–23.x6.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.

  1. Add the plugin to our workspace

    We’ll use nx add, which installs the package and runs the init generator to set up workspace-level dependencies and register the inference plugin in nx.json:

    bunx nx add @naxodev/nx-cloudflare

    This installs Wrangler v4, @cloudflare/workers-types, and Vitest as devDependencies, and adds @naxodev/nx-cloudflare/plugin to the plugins array in nx.json so Worker targets are inferred automatically.

  2. 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-world

    The generator creates a my-worker/ directory with a wrangler.jsonc config, a src/index.ts entry point, and a package.json that registers the project with Nx. It also retargets the Wrangler $schema to the workspace root and strips redundant package scripts.

  3. Serve the Worker locally

    Now we can run the Worker in a local dev server:

    bunx nx serve my-worker

    This runs wrangler dev from the project root. The server is ready when Wrangler prints Ready on http://localhost:8787. Open that URL to see the Worker’s response.

  4. Deploy to Cloudflare

    When we’re ready to deploy, we run:

    bunx nx deploy my-worker

    This 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-run

    The --dry-run flag validates the deployment without publishing.

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).