# node-http-xhr

> Node.js XMLHttpRequest implementation using http.request()

Latest version **1.3.4** (published 2017-06-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install node-http-xhr
pnpm add node-http-xhr
yarn add node-http-xhr
bun add node-http-xhr
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.4 |
| Published | 2017-06-30 |
| First published | 2017-06-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Stan Zhang |
| Maintainers | aspyrx |
| Keywords | node, nodejs, http, https, xhr, xmlhttprequest, http.request, https.request, request |

## Links

- npm: https://www.npmjs.com/package/node-http-xhr
- Repository: https://github.com/aspyrx/node-http-xhr
- Homepage: https://github.com/aspyrx/node-http-xhr#readme
- Issues: https://github.com/aspyrx/node-http-xhr/issues
- npm.io page: https://npm.io/package/node-http-xhr

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.3.4 (latest) — 2017-06-30
- 1.3.3 — 2017-06-19
- 1.3.2 — 2017-06-17
- 1.3.1 — 2017-06-15
- 1.3.0 — 2017-06-13
- 1.2.1 — 2017-06-07
- 1.1.0 — 2017-06-05
- 1.0.0 — 2017-06-02

## README

# `node-http-xhr`

[![npm][npm-status]][npm]

[![Build Status][build-status]][travis]

An implementation of [`XMLHttpRequest`][mdn-xhr] for [`node.js`][nodejs] using
the [`http.request`][nodejs-http] API.

[npm-status]:https://nodei.co/npm/node-http-xhr.png
[npm]:https://www.npmjs.com/package/node-http-xhr
[build-status]: https://travis-ci.org/aspyrx/node-http-xhr.svg?branch=master
[travis]: https://travis-ci.org/aspyrx/node-http-xhr
[mdn-xhr]: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
[nodejs]: https://nodejs.org
[nodejs-http]: https://nodejs.org/dist/latest/docs/api/http.html

## Motivation

This package was written to provide the `XMLHttpRequest` API to test browser
code that is being tested in a `node.js` environment.

## Installation

```sh
npm install --save node-http-xhr
```

## Usage

```javascript
// 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:

```sh
npm run doc
```

The `html` documentation will be placed in `doc/`.

### Tests

```sh
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.

---
_Source: https://npm.io/package/node-http-xhr · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
