Skip to content

Document that Web Crypto and Node.js crypto APIs differ in Workers and can break copy-pasted Node examples #6883

Description

@tanhanet

What documentation change is needed?

Cloudflare Workers supports Web Standard APIs first, but many developers copy Node.js examples for hashing, signing, random bytes, or key generation and expect them to work unchanged in Workers.

The docs cover APIs individually, but it is still easy to miss that crypto.subtle in Workers is not the same usage pattern as Node's crypto module, and that examples written for Node often fail or require adaptation.

A short clarification page or note in the Workers docs would help prevent confusion when developers move code from Node.js tutorials or npm package examples into Workers.

What problem does this solve?

A common source of confusion is code like this:

  • Node.js examples using createHash, createHmac, randomBytes, or createSign
  • assumptions that Buffer-based examples work unchanged
  • expectations that all crypto examples found online apply directly to Workers runtime

In Workers, developers often need to use:

  • Web Crypto APIs such as crypto.subtle.digest()
  • TextEncoder / TextDecoder
  • Workers-compatible libraries or compatibility settings where relevant

Without a clear note, this can lead to trial-and-error debugging and the impression that Workers crypto support is incomplete, when the actual issue is API mismatch.

Suggested improvement

Please add a documentation note or guide that clearly explains:

  1. Workers primarily uses Web Crypto / web-standard runtime APIs
  2. Node.js crypto examples often need adjustment before they work in Workers
  3. a few side-by-side examples for common tasks:
    • SHA-256 hashing
    • HMAC signing
    • secure random value generation
  4. when Node compatibility features help, and when they still do not make all Node examples portable as-is

Where should this appear?

Possible locations:

  • Workers runtime API docs
  • Node.js compatibility docs for Workers
  • a troubleshooting or migration guide for "moving Node code to Workers"

Additional context

This would be especially helpful for developers migrating server-side code or using package documentation that assumes a full Node.js runtime.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions