node-http-xhr
Node.js XMLHttpRequest implementation using http.request()
Last updated 7 years ago by aspyrx .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install node-http-xhr 
SYNC missed versions from official npm registry.

node-http-xhr

npm

Build Status

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-xhr

Usage

// 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 doc

The html documentation will be placed in doc/.

Tests

npm test

Known issues

Currently, some features are lacking:

  • Some ProgressAPI events (loadstart, loadend, progress)
  • responseType values other than '' or 'text' and corresponding parsing
    • As a result of the above, overrideMimeType() isn't very useful
  • setRequestHeader() doesn't check for forbidden headers.
  • withCredentials is defined as an instance property, but doesn't do anything since there's no use case for CORS-like requests in node.js right now.

Current Tags

  • 1.3.4                                ...           latest (7 years ago)

8 Versions

  • 1.3.4                                ...           7 years ago
  • 1.3.3                                ...           7 years ago
  • 1.3.2                                ...           7 years ago
  • 1.3.1                                ...           7 years ago
  • 1.3.0                                ...           7 years ago
  • 1.2.1                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (11)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |