Registry / http-networking / xmlhttprequest

xmlhttprequest

JSON →
library1.8.0jsnpmunverified

The `xmlhttprequest` package provides a CommonJS-compatible implementation of the browser's XMLHttpRequest (XHR) object for Node.js environments. Its primary goal is to enable developers to reuse JavaScript code designed for browsers, particularly older libraries, within a Node.js context by emulating the standard XHR API. The latest version, 1.8.0, was published over a decade ago (October 2015), and the package has since been largely unmaintained. It conforms to the XMLHttpRequest Level 1 specification, lacking many features found in modern XMLHttpRequest Level 2 or the Fetch API. Due to its abandoned status and the existence of more actively maintained alternatives like `xhr2` or `w3c-xmlhttprequest`, new projects should generally avoid this package. Its release cadence was irregular, tied to core code changes or W3C spec conformity, but no significant updates have occurred in years. Key differentiators include its simple, direct emulation for older Node.js versions (0.4.0+) and minimal dependencies.

npm install xmlhttprequest
INSTALL
IMPORT
SIG · XMLHTTPREQUEST
X
xmlhttprequest
http-networkingjavascriptv1.8.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

XMLHttpRequest
const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
import { XMLHttpRequest } from 'xmlhttprequest';
This package is CommonJS-only and does not support ES modules. The XMLHttpRequest constructor is exported as a property of the main module export.

Demonstrates how to import the XMLHttpRequest constructor using CommonJS and perform a basic asynchronous GET request to an example URL.

const XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; const xhr = new XMLHttpRequest(); xhr.open('GET', 'https://example.com/api/data', true); // `true` for asynchronous request xhr.onload = function () { if (xhr.status >= 200 && xhr.status < 300) { console.log('Response:', xhr.responseText); } else { console.error('Request failed with status:', xhr.status, xhr.statusText); } }; xhr.onerror = function () { console.error('Network error or CORS issue occurred.'); }; xhr.send(); console.log('XMLHttpRequest instance created and request sent.');
Debug
Known issues
breakingThis package is unmaintained and considered abandoned. It has not received updates since 2015 and does not implement modern XMLHttpRequest Level 2 features or security fixes. Consider using alternatives like `xhr2` or Node.js's native `http`/`https` modules, or the `undici` package for robust HTTP client functionality.
fix
Migrate to `xhr2` (`npm i xhr2`) or `w3c-xmlhttprequest` (`npm i w3c-xmlhttprequest`) for a more up-to-date and maintained XHR implementation, or use native Node.js HTTP clients.
affects: >=1.8.0
gotchaThe package only conforms to XMLHttpRequest Level 1. Many features common in modern browsers and expected in current web development, such as `FormData`, `Blob`, `file://` URIs, specific progress events (e.g., upload), `responseType='json'`, and proper cookie persistence, are not implemented or behave unexpectedly.
fix
Be aware of missing features. For modern web APIs, this library is insufficient. Use alternative XHR polyfills or Node.js native `http`/`https` for full control.
affects: <=1.8.0
gotchaSynchronous XMLHttpRequest requests (where the third argument to `open()` is `false`) are known to freeze the Node.js event loop while waiting for a response. They also have reported issues with not setting headers properly.
fix
Always prefer asynchronous requests by setting the third argument of `open()` to `true` (or omitting it, as `true` is the default). Avoid synchronous XHR in Node.js entirely.
affects: <=1.8.0
gotchaDue to Node.js's case-sensitive module resolution on Linux and other Unix-like systems, using an incorrect casing in the `require()` path (e.g., `require("XMLHttpRequest")`) will result in a 'Cannot find module' error.
fix
Always use the exact lowercase string `"xmlhttprequest"` in your `require()` calls: `require("xmlhttprequest")`.
affects: <=1.8.0
Errors
Common errors & fixes
Error: Cannot find module 'XMLHttpRequest'
The `require()` path used an incorrect casing for the package name. Node.js module resolution is case-sensitive on many operating systems.
fix
Ensure the package name in `require()` is all lowercase: `require('xmlhttprequest')`.
Node.js process freezes or becomes unresponsive during an HTTP request.
A synchronous XMLHttpRequest was used, which blocks the Node.js event loop until the request completes.
fix
Change the `open()` method call to be asynchronous: `xhr.open('GET', url, true);` (or omit the third argument as `true` is default).
Upgrade
Version history
1.8.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
27 hits · last 30 days
node
22
OpenAI (training)
1
Resources
xmlhttprequest — npm install xmlhttprequest · libregistry