Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-http-xhr

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-http-xhr

Node.js XMLHttpRequest implementation using http.request()

  • 1.3.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.4K
decreased by-10.91%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 30 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc