# Worker Environments

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

## Origin

Worker Environments 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 Environments or Worker Contexts.

To see which vendors and APIs are available, check out the State of Worker Environments below. See the example below for a minimal HTTP server:

self.addEventListener('fetch', event => {
event.respondWith(new Response('Hello World'));
});


Minimal example of a server written in a Worker Environment.

## Backend for Frontend

Worker Environments 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 worlds of node and browsers have diverged1. Worker Environments are bringing them back together.

This is good news for Frontend Developers in particular: The knowledge ac- and required for building offline web applications can now be applied to writing HTTP servers — and so can the tools.

## State of Worker Environments

There is currently one fully-featured Worker Environment and one alternative being implemented. There are four offline testing and development implementations.

Cloudflare Workers is the most complete Worker Environment. It is currently the only one implementing the global fetch event, bringing it on par with Service Workers. However, Deno is expected to follow shortly.

Service WorkersCloudflare WorkersDeno CLIDeno DeployMiniflarecfworker/devCloudworkercloudflare-
worker-local
DomainBrowserEdgeServerEdgeTesting, DevTesting, 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

### 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 environments.

APIService WorkersCloudflare WorkersDeno CLIDeno DeployMiniflarecfworker/devCloudworkercloudflare-
worker-local
fetch event👨‍💻
install event🚫🚫🚫🚫🚫
activate event🚫🚫🚫🚫🚫
URL APIℹ️
Fetch API
Abort Controller👨‍💻👨‍💻👨‍💻
URL Pattern APIℹ️👨‍💻
Encoding API
Streams APIℹ️ℹ️ℹ️🚫
Encoding Streamsℹ️🚫🚫🚫🚫🚫
Web Cryptography API🔜🔜
crypto.randomUUID()ℹ️
Cache APIℹ️ℹ️ℹ️ℹ️
Web Sockets APIℹ️ℹ️🚫🚫🚫
Location API👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻
Timers
queueMicrotaskℹ️
structuredCloneℹ️
IndexedDB🚫🚫🚫🚫🚫

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

APIService WorkersCloudflare WorkersDeno CLIDeno DeployMiniflarecfworker/devCloudworkercloudflare-
worker-local
KV Storage API👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻

### Non-Standard APIs

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

APIService WorkersCloudflare WorkersDeno CLIDeno DeployMiniflarecfworker/devCloudworkercloudflare-
worker-local
scheduled event🚫🚫🚫🚫🚫🚫
HTMLRewriter👨‍💻👨‍💻👨‍💻ℹ️👨‍💻👨‍💻
KV🚫🚫🚫ℹ️ℹ️
Durable Objects🚫🚫🚫🚫🚫🚫

### Frameworks

No HTTP Server is complete without a Web Framework for common tasks such as routing, sessions, authentication, and more. Unfortunately, Worker Environments do not have a framework at the level of polish that is common in Node.js, yet.

However, you can try cfworker/web which is a Web framework inspired by Koa and fastify.

You can also check out worker-tools, a collection of tools and libraries that achieve many of the same goals as a web framework, built by yours truly.

For more tools and libraries that work on Cloudflare Workers, check out Works on Workers.

## Contributing

Are you aware of any other Worker Environments 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. ↩︎