Package Exports
- node-http-xhr
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-http-xhr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
node-http-xhr
An implementation of XMLHttpRequest for node.js using
the http.request API.
Motivation
This package was written to provide the XMLHttpRequest API to test browser
code that is being tested in a node.js environment.
Installation
npm install --save node-http-xhrUsage
// Standalone usage
var XMLHttpRequest = require('node-http-xhr');
// Usage as global XHR constructor
global.XMLHttpRequest = require('node-http-xhr');
var req = new XMLHttpRequest();
// Event handlers via .on${event} properties:
req.onreadystatechange = function() {
console.log('readyState: ' + req.readyState);
};
// or using .addEventListener(event, handler):
req.addEventListener('load', function() {
console.log('response: ' + req.response);
});
req.open('GET', 'https://github.com/aspyrx', true);
req.send();Note about browser environments
If you use a bundler like browserify or webpack that follows the browser
field in package.json, the module will simply export window.XMLHttpRequest.
This is provided for sake of compatibility.
Development
Documentation
To generate documentation:
npm run docThe html documentation will be placed in doc/.
Tests
npm testKnown issues
Currently, some features are lacking:
- Some ProgressAPI events (
loadstart,loadend,progress) responseTypevalues other than''or'text'and corresponding parsing- As a result of the above,
overrideMimeType()isn't very useful
- As a result of the above,
setRequestHeader()doesn't check for forbidden headers.withCredentialsis defined as an instance property, but doesn't do anything since there's no use case for CORS-like requests innode.jsright now.
