How to Run Distlang Locally Using Workerd for Development
Ready to start building? Check the Distlang docs for setup instructions and CLI details.
What Does “Run Distlang Locally Using workerd” Mean?
Running Distlang locally using workerd is the development workflow where the Distlang CLI compiles a JavaScript worker app and starts it on your machine using Cloudflare’s open-source Workers runtime. You can then test request handling, environment variables, background tasks, and instrumentation code before packaging or deploying.
The important distinction: workerd is not Node.js. It is a JavaScript/Wasm runtime based on the same code that powers Cloudflare Workers. It supports Web-standard APIs like fetch(), Request, and Response, but it does not provide Node-specific APIs. When you run Distlang locally with workerd, you are testing in a Workers-style environment, not a typical Node server.
In Cloudflare-native projects, this role is usually played by Wrangler (Cloudflare’s CLI). In Distlang projects, the Distlang CLI provides the build, run, and deploy workflow. For a deeper walkthrough of the CLI itself, see how to use Distlang CLI to run and debug workers locally.
Why Distlang Uses workerd for Local Development
Four reasons stand out.
Runtime fidelity. Before workerd existed, local Workers development relied on JavaScript reimplementations of the Workers API. These had subtle mismatches. Cloudflare’s engineering team explained that Miniflare 3 switched to workerd specifically to eliminate those gaps. Running Distlang locally with workerd gives you the same benefit: your local runtime behaves closer to the deployed worker environment than any Node-based polyfill.
Fast feedback. Deploying on every code change is slow. When Cloudflare moved Wrangler v3 to local-first development, they reported a 10x reduction in startup time and 60x faster script reloads compared to remote mode. Local workerd development gives Distlang users that same speed advantage.
Portability testing. Distlang’s CLI can compile JavaScript worker apps and package them for Cloudflare or Distlang-hosted deployments. Running locally using workerd lets you verify the app works in a worker-style runtime before committing to a deployment target.
Serverless lifecycle testing. Short-lived handlers have tricky lifecycle behavior. If your app fires async work (like a metrics flush) without awaiting it or scheduling it through ctx.waitUntil(), that work can be canceled when the invocation ends. Local workerd development surfaces these bugs before they silently eat data in production.
How the Local Development Loop Works
Most guides collapse local development into a single “run locally” step. That hides where problems actually occur. A better mental model breaks local Distlang development into three layers.
Layer 1: Build
The Distlang CLI compiles or bundles the JavaScript worker app. This layer answers: Is the source code valid? Did imports resolve? Is there a usable worker bundle?
A build failure here means the code never reaches the runtime. Check syntax, missing dependencies, and import paths first.
Layer 2: Runtime
workerd executes the bundled worker on your machine. This layer answers: Does the app handle requests correctly in a Workers-style environment? Are there Node-only API assumptions that break outside Node?
If you find old Stack Overflow answers saying Cloudflare Workers cannot run locally, check the date. A widely cited 2018 answer said exactly that, but workerd changed the story entirely.
Layer 3: Resources
This is where bindings, secrets, APIs, metrics endpoints, and databases either get simulated locally or connect to remote services. Cloudflare’s local development documentation explicitly separates Worker execution from bindings, and Distlang follows the same principle. Your code may run on your machine while its dependencies are local stubs, staging resources, or hosted APIs.
When something fails during local Distlang development with workerd, asking “which layer broke?” gets you to the answer faster than restarting everything.
What Runs Locally vs. What May Connect Remotely
This table covers the typical components of a Distlang worker app and where they live during local development.
| Component | Usually local? | What to verify |
|---|---|---|
| Worker code execution | Yes | Confirm it runs in workerd, not just a Node dev server |
| Build output | Yes | Did the Distlang CLI produce a valid worker bundle? |
| Environment variables and secrets | Local files | Are tokens and URLs present in your local env/secret config? |
| Metrics ingestion (Distlang Metrics) | External hosted API | Use a staging or dev token to avoid polluting production dashboards |
| Storage bindings (KV, R2, D1) | Local simulation by default | Check whether your app needs seeded data or remote staging resources |
| Background tasks | Depends on runtime lifecycle | Await critical work or schedule it through waitUntil-style patterns |
| Third-party APIs | Remote | External HTTP calls hit real endpoints unless you mock them |
The key insight from practitioners: in the Cloudflare remote-bindings GitHub discussion, developers repeatedly described the pain of empty local simulations. Large KV datasets are impractical to replicate locally, feature flags drift from staging, and some services cannot be simulated at all. Cloudflare’s response was remote bindings, which became generally available in September 2025. The principle applies to Distlang too: run code locally, but connect to real resources selectively when local stubs are not enough.
If you are instrumenting a Cloudflare Worker with Distlang Metrics, the Cloudflare quickstart covers the specific integration pattern.
When to Use Local Simulation vs. Remote Resources
| Use case | Recommended approach | Why |
|---|---|---|
| Request routing, pure business logic | Local-only | Fastest iteration, no external dependencies |
| Metrics instrumentation shape | Local app, staging metrics endpoint | Confirms payloads and flush behavior without polluting production |
| Large KV/R2/D1 datasets | Local code, remote staging resource | Seeding large data locally is impractical |
| Provider-only services (AI, image processing) | Local code, remote resource | These backends are hard to simulate locally |
| Destructive writes (deletes, migrations) | Local-only or isolated staging | Never point destructive tests at production |
| Multi-worker service boundaries | Single dev session with service bindings | Only the primary worker is exposed over HTTP in single-command mode |
Cloudflare’s own documentation recommends local code execution with selective remote bindings over full remote development for faster iteration. That same guidance applies when you run Distlang locally using workerd for development.
Local Development Checklist
When running Distlang locally with workerd, follow this sequence:
- Install the Distlang CLI and project dependencies. Confirm your CLI version supports local workerd execution.
- Set up local environment variables and secrets. Store tokens, API keys, and service URLs in a local env file. Do not commit secret files to version control.
- Run the Distlang CLI’s local development command. The CLI will build your app and start it in workerd.
- Open the local URL printed in the terminal.
- Trigger a test request and watch the terminal for logs.
- Verify side effects. If the app writes to storage, sends metrics, or calls external APIs, confirm those operations completed.
- Check background work. If your app uses metrics flushing or post-response tasks, confirm the flush path is awaited or scheduled through the runtime lifecycle.
For metrics-specific verification, the Distlang Metrics quickstart walks through the full path from instrumentation to dashboard.
Common Mistakes
Treating workerd like Node.js
Practitioners on Reddit frequently report confusion when framework tooling assumes Node.js while the actual deployment target is a Workers runtime. If a dependency relies on Node-only APIs (like fs, net, or child_process), it will break in workerd. Test in the workerd path, not just a framework dev server.
Forgetting local secrets
Local workerd development only works if local secrets match the app’s expectations. A missing metrics token or API key means the runtime starts fine but ingestion or external calls silently fail. Keep a .dev.vars or .env file with the values your app needs, and keep it out of git.
Assuming local resources contain real data
Local binding simulations start empty. If your app queries a KV namespace or D1 database, those local stubs will return nothing unless you seed them. Decide early whether you need local seed data or a remote staging connection.
Losing background work to cancellation
This is the most common source of missing metrics in serverless handlers. Async work that is neither awaited nor passed to ctx.waitUntil() can be canceled when the handler finishes. HTTP-triggered workers get up to 30 seconds of post-response execution through waitUntil, but unawaited promises get no such guarantee. For reliable patterns, see ctx.waitUntil patterns for workerd tasks.
Testing only one worker when production uses multiple
Distlang is built for distributed applications. If your production setup involves multiple workers communicating through service bindings, running a single worker locally will not catch routing or inter-service issues. In Cloudflare’s model, only the primary worker gets exposed over HTTP in a single dev session, and additional workers are reached through service bindings.
Troubleshooting Quick Reference
Local server does not start: Check that dependencies are installed, the Distlang CLI version supports local workerd mode, and no other process is using the same port.
Code works in Node but fails locally: Look for Node-specific API usage. The workerd runtime is standards-based, not Node-compatible.
Metrics or logs disappear: Check whether async flushes are awaited or scheduled. If metrics are still missing after fixing lifecycle issues, walk through debugging missing metrics for common ingestion failure causes.
Local data looks empty: Local simulations start without data. Seed them manually or switch to a staging resource for that binding. For details on how buffering and flush work in serverless contexts, review the flush strategies guide.
Ready to move past local? Once your app runs cleanly, you can deploy to a hosted staging URL for integration testing before production.
Related Terms
workerd: Cloudflare’s open-source JavaScript/Wasm server runtime (pronounced “worker-dee”). It powers both Cloudflare Workers in production and local development environments. Direct usage requires a Cap’n Proto config file, which is why most developers use a CLI abstraction instead.
Distlang CLI: The command-line tool that compiles JavaScript worker apps, runs them locally using workerd, and packages them for deployment to Cloudflare or Distlang-hosted targets.
Binding: An interface through which worker code accesses resources like KV, R2, D1, Queues, and Durable Objects via the env object. Bindings can connect to local simulations or remote resources.
Remote binding: A configuration that lets locally running worker code connect to deployed resources on a per-binding basis, useful when local simulations are insufficient.
ctx.waitUntil(): A Workers Context API method that extends an invocation so background work can continue after a response returns. Critical for metrics flushing and post-response tasks.
Miniflare: Cloudflare’s local Workers simulator. Modern versions use workerd under the hood rather than reimplementing runtime APIs in JavaScript.
FAQ
Is workerd the same as Node.js?
No. workerd is a Workers-style JavaScript/Wasm runtime based on the same code as Cloudflare Workers. It supports Web-standard APIs like fetch() but does not include Node-specific modules. If your code only works in Node, it may break when you run Distlang locally using workerd.
Can I run workerd directly without the Distlang CLI?
Yes. workerd can be run with workerd serve my-config.capnp, but that requires writing a Cap’n Proto configuration file. For application development, the Distlang CLI handles this plumbing so you do not need to manage runtime configs manually.
Are my bindings automatically local when I run locally?
By default, bindings connect to local simulations. But those simulations start empty, which is why some developers configure specific bindings to connect to remote staging resources. The decision depends on whether your tests need realistic data.
Should I use production resources during local development?
Avoid it. Use local simulations for fast isolated testing and staging resources when you need real data shape or provider-only behavior. Never point destructive tests at production.
Why did my metrics not flush during local testing?
The most likely cause is unawaited async work. In Workers-style runtimes, promises that are neither awaited nor registered with ctx.waitUntil() can be canceled when the handler finishes. The post-invocation window for HTTP-triggered workers is 30 seconds.
How close is local workerd behavior to production?
Close, but not identical. workerd runs the same runtime code as Cloudflare Workers, which eliminates the API-level mismatches that older tools had. However, local simulations for bindings may behave differently from remote resources, and network conditions, regional routing, and rate limits only exist in deployed environments.
Do I still need staging or remote testing?
Yes, for anything that depends on real data, provider-only services, multi-region behavior, or integration with external APIs. Local workerd development covers code correctness and runtime compatibility. Staging covers system-level behavior.
Start building with the Distlang JavaScript client to add metrics instrumentation to your worker apps, then run Distlang locally using workerd to verify everything before you deploy.