This document aims to list places where an API to address similar use cases is developed differently in different environments. These differences sometimes make it hard to write code which spans environments, and sometimes justify investigation into a shared solution.
This initial document includes Node and Web APIs, but PRs are welcome to document additional environments as well. Some of the entries here may be poor analogies--if so, please make a PR to clarify things!
For interfaces to be considered analogous, there should be some evidence that developers today are using them in a shared way today, e.g., a widely-used polyfill of one in terms of the other, or a widely-used higher-level API based on them both.
- Purpose: Register callbacks for certain events
- Web API: EventTarget
- Node.js API: EventEmitter
- Mitigation strategies: TODO (Observables? Polyfills? How do programmers write isomorphic code today?)
- Purpose: Incremental access to binary data, e.g., from over the network
- Web API: WHATWG Streams API
- Node.js API: Node Streams
- Mitigation strategies: whatwg-stream effort to implement WHATWG Streams as a Node.js module;
readable-stream
provides Node streams for the Web
- Purpose: Interaction with octet streams
- Web API: ArrayBuffer API
- Node.js API Buffer API
- Mitigation strategies: Newer versions of Node.js have Buffer.from(arrayBuffer) method and the
Buffer
is an instance of a TypedArray with a few caveats.
- Purpose: Open, read and write to an HTTP, HTTPS, HTTP2 connection
- Web API:
fetch()
- Node.js API: http, https, http2
- Mitigation strategies: node-fetch polyfill to support fetch from Node.js, stream-http implementation of the Node HTTP module for browsers
- Purpose: Basic cryptography algorithms, available as a standard library
- Web API: WebCrypto's
crypto.subtle
SubtleCrypto - Node.js API: The
crypto
module - Mitigation strategies: npm packages like uuid detect where they are running and use whatever APIs are available. There are various WebCrypto polyfills/shims in npm, but none seem to be very widely used.
- Purpose: Read and write files on the filesystem
- Web API: File API, in-progress WritableFile proposal
- Node.js API:
fs
module - Mitigation strategies: TODO (Unclear if these are analogous enough to actually ever be bridged in practice)
- Purpose: Provide APIs which cancel asynchronous processes, asynchronous requests, promises, etc.
- Web API: AbortController
- Node API: ??
- Mitigation strategies: ??