Everything you need to know
Web APIs, integral to browser-based applications, offer tools like fetch and WebSocket for web interactions. While these have become browser standards, their support in server-side environments like Node.js has been inconsistent.
In earlier versions of Node.js, Web standard APIs commonly available in browsers weren’t natively supported. Developers had to rely on third-party packages like node-fetch to replicate this functionality. However, from Node.js v18, there’s experimental support for the fetch API, potentially eliminating the need for these packages.
Bun simplifies this by offering built-in support for these Web standard APIs. Developers can directly use stable fetch, Request, Response, WebSocket and other browser-like APIs without any additional packages. Furthermore, Bun’s native implementation of these Web APIs ensures they are faster and more reliable compared to third-party alternatives.
Here’s an example compatible with both Node.js (v18 and above) and Bun. While it’s experimental in Node.js, the same functionality is stable in Bun:
Read more here: Source link
