Logo

Worker Runtimes

Worker Runtimes are the new standard for writing HTTP servers in JavaScript.

Learn More Contribute

Worker Runtimes are the new standard for writing HTTP servers in JavaScript.

Origin

Worker Runtimes are an adaptation of the Service Workers API, which is a browser standard for offline web applications. To give web developers more freedom over offline experiences, the specification includes a (minimal) HTTP server. Since it was published, other vendors have implemented this API for servers that run in the cloud β€” or on the edge in the case of Cloudflare Workers.

Typically, they also implement other browser APIs such as Fetch, Streams, and Web Cryptography, making their global scope similar to that of a Service Worker. We call them Worker Runtimes or Worker Contexts.

To see which vendors and APIs are available, check out the State of Worker Runtimes below.

self.addEventListener('fetch', event => {
  event.respondWith(new Response('Hello World', {
    headers: { 'Content-Type': 'text/plain' }
  }));
})

Example of a minimal HTTP server using Service Workers API

Since originally writing this, both Deno and Cloudflare Workers have dropped support for the pattern shown above. While the Request and Response classes remain, the global fetch event and respondWith method do not. The reasons are difficult to ascertain, but it seems it was deemed too confusing for beginners.

State of Worker Runtimes

There are currently two production quality Worker Runtimes. There are multiple offline, testing, and development implementations. Cloudflare Workers was the first, and is the most battle-tested Worker Environment. Deno Deploy is a close second.

Cloudflare Workers Deno Deploy Miniflare



Β Service WorkersCloudflare WorkersDeno CLIDeno DeployMiniflarecfworker/devcloudflare-
worker-local
DomainBrowserEdgeServerEdgeTesting, DevTesting, DevTesting, Dev
Open Sourceβœ…πŸš«βœ…β„ΉοΈβœ…βœ…βœ…
1.0βœ…βœ…βœ…βœ…βœ…βœ…βœ…

Legend

βœ…
Supported
ℹ️
Partial support / attention required
πŸ”œ
Implementation in progress
πŸ‘¨β€πŸ’»
Supported via 3rd party library / polyfill
❓
Support to be determined
🚫
Not supported
πŸ”™
Backwards compatibility only
πŸ’€
Support dropped

Browser APIs

The center piece of any Worker Environment is an implementation of the global fetch event. Implementations of other browser APIs are necessary for bridging the gap between different worker runtimes.

Β Service WorkersCloudflare WorkersDeno CLIDeno DeployMiniflarecfworker/devcloudflare-
worker-local
fetch eventβœ…πŸ”™πŸ‘¨β€πŸ’»β“βœ…βœ…βœ…
URL APIβœ…β„ΉοΈβœ…βœ…βœ…βœ…βœ…
Fetch APIβœ…βœ…βœ…βœ…βœ…βœ…βœ…
Abort Controller/Signalβœ…βœ…βœ…βœ…βœ…πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»
URL Pattern APIβ„ΉοΈβœ…βœ…βœ…πŸ”œπŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»
Encoding APIβœ…βœ…βœ…βœ…βœ…βœ…βœ…
Streams APIβ„ΉοΈβ„ΉοΈβœ…βœ…β„ΉοΈβ„ΉοΈπŸš«
Encoding Streamsβ„ΉοΈπŸš«βœ…βœ…πŸš«πŸš«πŸš«
Compression Streamsβ„ΉοΈπŸš«βœ…β“πŸš«πŸš«πŸš«
Web Cryptography APIβœ…βœ…βœ…βœ…βœ…βœ…βœ…
crypto.randomUUID()β„ΉοΈβœ…βœ…βœ…βœ…β“β“
Cache APIβœ…β„ΉοΈβ“πŸ”œβ„ΉοΈβœ…β„ΉοΈ
WebSocket APIβœ…β„ΉοΈβœ…βœ…β„ΉοΈπŸš«πŸš«
Web Socket Streamβ“β“πŸ”œβ“β“πŸš«πŸš«
Location APIβœ…πŸ‘¨β€πŸ’»οΈβœ…βœ…πŸ‘¨β€πŸ’»οΈπŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»
queueMicrotaskβ„ΉοΈβœ…βœ…βœ…βœ…β“β“
structuredCloneβ„ΉοΈβœ…βœ…βœ…βœ…β“β“
EventTarget and Eventβœ…βœ…βœ…βœ…βœ…β“β“
Web Workers APIβœ…πŸš«βœ…βœ…πŸš«β“β“
Message Channelβœ…πŸš«βœ…βœ…πŸš«πŸš«πŸš«
Broadcast Channelβ„ΉοΈπŸš«πŸ”œβ„ΉοΈπŸš«πŸš«πŸš«
IndexedDBβœ…πŸš«β“β“πŸš«πŸš«πŸš«
Performance APIβœ…πŸš«βœ…βœ…β“β“β“

Working Drafts

The APIs below are either abandoned or do not have buy-in from major browser vendors. However, they can still be reasonable targets for 3rd party libraries, such as KV stores or cookie middleware.

Β Service WorkersCloudflare WorkersDeno CLIDeno DeployMiniflarecfworker/devcloudflare-
worker-local
KV Storage APIπŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»
Cookie Store APIβ„ΉοΈπŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»

Non-Standard APIs

These are useful APIs provided by one or more Worker Environment that aren’t on any standards track (including abandoned).

Β Service WorkersCloudflare WorkersDeno CLIDeno DeployMiniflarecfworker/devcloudflare-
worker-local
scheduled eventπŸš«βœ…πŸš«πŸš«βœ…πŸš«πŸš«
HTMLRewriterπŸ‘¨β€πŸ’»βœ…πŸ‘¨β€πŸ’»πŸ‘¨β€πŸ’»β„ΉοΈβœ…πŸ‘¨β€πŸ’»
KVπŸš«βœ…πŸš«πŸš«βœ…βœ…β„ΉοΈ
Durable ObjectsπŸš«βœ…πŸš«πŸš«βœ…πŸš«πŸš«
crypto.DigestStreamπŸš«βœ…πŸš«πŸš«βœ…πŸš«πŸš«
Ed25519 via WebCryptoπŸš«βœ…πŸš«πŸš«βœ…πŸš«πŸš«

General Capabilities, Non-Standard

These are some general capabilities provided by one or more Worker Environment that share similarities but aren’t tied to a specific API.

Β Service WorkersCloudflare WorkersDeno CLIDeno DeployMiniflarecfworker/devcloudflare-
worker-local
File system accessπŸš«πŸš«βœ…β„ΉοΈπŸš«πŸš«πŸš«
Connect TCPπŸš«πŸ”œβœ…βœ…πŸ”œπŸš«πŸš«
Connect UDPπŸš«πŸ”œπŸ”œπŸ”œπŸ”œπŸš«πŸš«
WebSockets (Server)πŸš«βœ…βœ…β“βœ…πŸš«πŸš«

Backend for Frontend

Worker Runtimes fulfill the original promise of NodeJS: To use one language and share code between client and server. In practice, this never came to be. Instead the APIs of node and browsers have diverged1. Worker Runtimes are bringing them back together.

This is good news for Frontend Developers in particular: The knowledge acquired for building (offline) web applications can now be applied to writing HTTP servers β€” and so can the tools:

Worker Tools Logo

Tools

No HTTP Server is complete without a web framework for common tasks such as routing, sessions, authentication, and more.

Worker Tools is a collection of tools and libraries for writing web servers, built specifically for Worker Runtimes. They can be used independently, or as a complete framework via Worker Tools / Shed.

Contributing

Are you aware of any other Worker Runtimes available or in development? Did you find any inaccuracies in the tables above? Open a PR in the workers.js.org repository!


  1. Node and the browser have diverged due to a lack of browser APIs for many crucial components, including HTTP, streams, file access, and more more. A lot has changed since then. Standards have been written for all of these and more, often informed by the experience of using the node-equivalent.Β ↩︎