`unxhr` is a Node.js library that provides an emulation of the browser's native `XMLHttpRequest` object, enabling both synchronous and asynchronous HTTP requests within Node.js environments. Currently at version 1.2.0, its release cadence is moderate, with recent updates primarily focused on bug fixes and infrastructure improvements. The project is a fork of the original `XMLHttpRequest` package, specifically developed to achieve compliance with the XMLHttpRequest Level 2 specifications. Key differentiators include its complete lack of external dependencies, support for standard HTTP methods (GET, POST, PUT, DELETE), handling of binary data through JavaScript typed arrays, automatic redirection following, and limited support for the `file://` protocol. It serves as a bridge for codebases that expect browser-like XHR behavior in a Node.js context, despite some inherent limitations compared to a full browser implementation.
npm install unxhrVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic asynchronous HTTP GET request using `unxhr`'s `XMLHttpRequest` emulation, including event handling for response and errors, wrapped in a Promise.
Prioritize asynchronous requests whenever possible. If synchronous behavior is strictly required, ensure it's used in non-critical paths or dedicated worker threads to minimize impact on the main event loop.
Always use asynchronous requests for scenarios requiring reliable HTTP header manipulation. If synchronous is unavoidable, thoroughly test header transmission.
For local file access, prefer Node.js's native `fs` module for reliable and robust file system interactions. Avoid `unxhr` for `file://` protocol access if file encoding or integrity is critical.
Review the 'Known Issues / Missing Features' section in the package README. For advanced XHR features or a more complete HTTP client, consider using Node.js-native libraries like `node-fetch` or `axios`.
Ensure you are using `const XMLHttpRequest = require('unxhr').XMLHttpRequest;` and that `XMLHttpRequest` is in scope where you are attempting to instantiate it.For `unxhr` v1.2.0 and above, the default `maxBuffer` is 100MB. If you encounter this, increase the buffer size by setting the `UNXHR_MAX_BUFFER` environment variable (e.g., `UNXHR_MAX_BUFFER=200000000` for 200MB).
Verify network connectivity, check the target URL/host for correctness, and ensure no firewalls or proxies are blocking the request. Inspect the `onerror` event for more specific details if available.
No dependency data recorded yet.