{"id":14318,"library":"w3c-xmlhttprequest","title":"W3C XMLHttpRequest for Node.js","description":"w3c-xmlhttprequest is a Node.js library that provides a server-side implementation of the XMLHttpRequest (XHR) API, faithfully adhering to the W3C/WHATWG Living Standard. It allows Node.js applications to make HTTP requests using an API familiar to front-end developers, bridging the gap between browser and server environments for XHR-based logic. The current stable version is 3.0.4. The project appears to have an active maintenance cadence, with recent patch releases addressing bug fixes and type improvements. Its key differentiators include its strict adherence to the W3C specification, providing predictable behavior consistent with browser-based XHR, and its utility for isomorphic JavaScript codebases or server-side rendering where XHR patterns are preferred over Node.js native `http` or `https` modules.","status":"active","version":"3.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/ykzts/node-xmlhttprequest","tags":["javascript","xmlhttprequest","xhr","w3c","whatwg","typescript"],"install":[{"cmd":"npm install w3c-xmlhttprequest","lang":"bash","label":"npm"},{"cmd":"yarn add w3c-xmlhttprequest","lang":"bash","label":"yarn"},{"cmd":"pnpm add w3c-xmlhttprequest","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For CommonJS, use destructuring: `const { XMLHttpRequest } = require('w3c-xmlhttprequest');`. Versions 3.0.0-3.0.3 had a regression with `require` support, fixed in v3.0.4.","wrong":"const XMLHttpRequest = require('w3c-xmlhttprequest');","symbol":"XMLHttpRequest","correct":"import { XMLHttpRequest } from 'w3c-xmlhttprequest';"},{"note":"TypeScript types are included and available for explicit import.","symbol":"XMLHttpRequest (Type)","correct":"import type { XMLHttpRequest } from 'w3c-xmlhttprequest';"},{"note":"Often aliased to avoid conflict with global browser XMLHttpRequest types in mixed environments.","symbol":"NodeXMLHttpRequest","correct":"import { XMLHttpRequest as NodeXMLHttpRequest } from 'w3c-xmlhttprequest';"}],"quickstart":{"code":"import { XMLHttpRequest } from 'w3c-xmlhttprequest';\n\n// This example demonstrates a basic GET request using the server-side XMLHttpRequest.\n// It fetches content from a public URL and logs a confirmation message upon successful load.\n// Note that network requests in Node.js are asynchronous and non-blocking.\nconst client = new XMLHttpRequest();\nclient.open('GET', 'https://example.com/'); // Specify the HTTP method and the target URL.\nclient.addEventListener('load', () => {\n  // The 'load' event fires when the transaction is complete, regardless of success or failure.\n  // Check client.status for HTTP status codes (e.g., 200 for success).\n  console.log('Received an HTTP response. Status:', client.status);\n  if (client.status >= 200 && client.status < 300) {\n    console.log('Response data length:', client.responseText.length, 'characters.');\n  } else {\n    console.error('Request failed with status:', client.status);\n  }\n});\nclient.addEventListener('error', (event) => {\n  console.error('Network error occurred:', event);\n});\nclient.send(); // Initiates the request.\nconsole.log('GET request sent to example.com...'); // This will log immediately.","lang":"typescript","description":"Demonstrates a basic asynchronous GET request to 'https://example.com/', logging the HTTP status and response details upon completion, including error handling."},"warnings":[{"fix":"Review your XHR usage against the W3C specification, especially event listener registration and property access. Update code to conform to standard XHR behavior.","message":"Version 3.0.0 introduced significant changes to align strictly with the W3C/WHATWG Living Standard for XMLHttpRequest. This included enhanced support for features like `EventListenerObject`, `xhr.responseURL`, and `xhr.withCredentials`. Code relying on pre-v3.0.0 behavior or less strict XHR implementations may require updates.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Upgrade to `w3c-xmlhttprequest@3.0.4` or later for full CommonJS compatibility. Alternatively, use ES module `import` syntax if your environment supports it.","message":"Versions 3.0.0 through 3.0.3 of `w3c-xmlhttprequest` experienced a regression where `require()`-style CommonJS imports might not have functioned correctly or consistently, leading to errors when attempting to instantiate `XMLHttpRequest`.","severity":"gotcha","affected_versions":">=3.0.0 <3.0.4"},{"fix":"Ensure your Node.js environment meets the minimum requirement of 10.13.0 or upgrade Node.js.","message":"The package requires Node.js version 10.13.0 or higher. Using it with older Node.js versions will result in installation or runtime failures.","severity":"gotcha","affected_versions":"<10.13.0 Node.js"},{"fix":"Be mindful of environmental differences. For features like cookie management or complex credential handling, integrate appropriate Node.js HTTP utilities or proxy setups if needed.","message":"While `w3c-xmlhttprequest` mimics browser XHR, it operates in a server-side Node.js environment. This means certain browser-specific behaviors, like automatic cookie handling, credential management, or CORS preflight logic (beyond the base HTTP request), are not automatically replicated and might require manual implementation or additional Node.js modules.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"search_vec":"'3.0.4':66 'activ':73 'address':80 'adher':25,92 'allow':32 'api':23,41 'appear':69 'applic':34 'base':59,104 'behavior':99 'bridg':48 'browser':52,103 'browser-bas':102 'bug':81 'cadenc':75 'codebas':112 'consist':100 'current':62 'develop':47 'differenti':88 'end':46 'environ':55 'faith':24 'familiar':42 'fix':82 'front':45 'front-end':44 'gap':50 'http':37,126 'https':128 'implement':18 'improv':85 'includ':89 'isomorph':110 'javascript':111,130 'key':87 'librari':11 'live':29 'logic':60 'mainten':74 'make':36 'modul':129 'nativ':125 'node.js':4,10,33,124 'patch':78 'pattern':120 'predict':98 'prefer':122 'project':68 'provid':13,97 'recent':77 'releas':79 'render':117 'request':38 'server':16,54,115 'server-sid':15,114 'side':17,116 'specif':96 'stabl':63 'standard':30 'strict':91 'type':84 'typescript':135 'use':39 'util':108 'version':64 'w3c':1,6,95,133 'w3c-xmlhttprequest':5 'w3c/whatwg':28 'whatwg':134 'xhr':22,58,105,119,132 'xhr-base':57 'xmlhttprequest':2,7,21,131","created_at":"2026-04-20T01:59:05.112614+00:00","updated_at":"2026-04-20T01:59:05.112614+00:00","problems":[{"fix":"Ensure your package version is `w3c-xmlhttprequest@3.0.4` or higher for reliable CommonJS. Use destructuring for `require`: `const { XMLHttpRequest } = require('w3c-xmlhttprequest');`. For ESM, use `import { XMLHttpRequest } from 'w3c-xmlhttprequest';`.","cause":"Attempting to import `XMLHttpRequest` incorrectly using CommonJS `require()` in versions 3.0.0-3.0.3, or an incorrect import path.","error":"TypeError: XMLHttpRequest is not a constructor"},{"fix":"Verify that the argument passed to `addEventListener` is a valid function or an object implementing `handleEvent()`, as per the W3C EventTarget specification. This issue was addressed in beta versions leading to 3.0.0.","cause":"Passing an invalid or non-object argument to the `addEventListener` method, which expects an `EventListener` or `EventListenerObject`.","error":"TypeError: EventTarget.prototype.addEventListener called with a non-object argument"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/ykzts/node-xmlhttprequest","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/w3c-xmlhttprequest","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}