stream-http is a JavaScript library designed to provide a browser-compatible implementation of Node.js's native `http` module. Its primary goal is to replicate the Node.js HTTP client API and behavior as closely as possible within the constraints of web browsers, making it suitable for projects that need consistent HTTP request handling across Node.js and browser environments. The package is currently at version 3.2.0 and appears to be actively maintained, indicated by recent feature additions and ongoing support for modern browser capabilities. A key differentiator is its emphasis on streaming, delivering data to the caller before the request fully completes. It supports true streaming with backpressure in Chrome >= 58 via `fetch` and `WritableStream`, true streaming in Chrome >= 43 (via `fetch`) and Firefox >= 9 (via `moz-chunked-arraybuffer`), and pseudo-streaming in other supported browsers where the full response is held in memory but available early. It aims to replace `http-browserify`. It also provides additional browser-specific features like `message.url` for redirects and `options.withCredentials` for CORS requests.
npm install stream-httpVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to make a GET request using the `http.request` method, similar to Node.js. It shows how to set request options, handle the response stream, and process incoming data chunks until the request ends, including error handling.
Upgrade to a modern browser (IE11+) or use an older version of `stream-http` if IE10- support is critical.
Use the default `options.mode` for general purpose requests, especially with binary data or when accurate Content-Type headers are critical. Only use 'prefer-streaming' for known text data.
Review the `stream-http` documentation and browser API capabilities for specific features that might not be fully supported. Adjust application logic to account for browser-specific behaviors like silent redirects.
Ensure you are using the correct `import` or `require` statement for your module system (e.g., `import http from 'stream-http'` for ESM, `const http = require('stream-http')` for CommonJS).Ensure the server you are requesting from is configured to send `Access-Control-Allow-Origin` headers that permit requests from your domain. For requests that need to send cookies or authentication, set `options.withCredentials = true` in your request configuration.
Remove or set `options.mode` to 'default' (or `undefined`) unless you explicitly understand and accept the content-type reporting inaccuracies for streaming benefits. Verify browser compatibility for your chosen `mode`.
No dependency data recorded yet.