Registry / http-networking / http-browserify

http-browserify

JSON →
library1.7.0jsnpmunverified

http-browserify provides a browser-compatible implementation of Node.js's native `http` module, specifically designed to be used with Browserify. When bundling browser-side code with Browserify, this package allows `require('http')` calls to function correctly, enabling HTTP requests from the browser environment using a Node.js-like API. The current stable version is 1.7.0. This package is part of the broader Browserify ecosystem, which focuses on bringing Node.js modules to the browser. It implements core HTTP client functionalities such as `http.request`, `http.get`, and methods for managing headers and data streams. Key differentiators include its tight integration with Browserify's module resolution and its effort to mimic the Node.js API, making it easy for developers to port server-side HTTP logic to the client.

npm install http-browserify
INSTALL
IMPORT
SIG · HTTP-BROWSERIFY
H
http-browserify
http-networkingjavascriptv1.7.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

http
const http = require('http');
This package is designed for CommonJS environments and Browserify bundling. It directly shims Node.js's 'http' module.
http
var bundle = browserify({ require : { http : 'http-browserify' } });
var bundle = browserify().require('http-browserify', { expose: 'http' });
When using Browserify, `http-browserify` typically transparently replaces the Node.js 'http' module. If explicit mapping is needed, use the `require` option during bundling as shown.

Demonstrates how to perform a basic GET request using the `http` module API in a Browserify-bundled environment, handling data and end events.

const http = require('http'); const resultDiv = document.createElement('div'); resultDiv.id = 'result'; document.body.appendChild(resultDiv); // Mock server response for demonstration in a real browserify context // In a true browser environment, this would hit an actual endpoint. const mockEndpoint = '/beep'; console.log(`Making a GET request to ${mockEndpoint}`); http.get({ path : mockEndpoint }, function (res) { resultDiv.innerHTML += `GET ${mockEndpoint}<br>`; res.on('data', function (buf) { resultDiv.innerHTML += `Received data: ${buf}<br>`; }); res.on('end', function () { resultDiv.innerHTML += '<br>__END__'; console.log('Request ended.'); }); res.on('error', function(err) { resultDiv.innerHTML += `Error: ${err.message}<br>`; console.error('Request error:', err); }); }); // To make this runnable without a backend, you'd typically intercept the request // For a real-world scenario, '/beep' would be served by a backend. // This example demonstrates the client-side API usage.
Debug
Known issues
gotchaMultipart streaming responses are buffered in older browsers (Internet Explorer 5.5-9, Opera 10.6). Modern browsers (Firefox 3.5+, Chrome 7.0+, Safari 5.0+) provide unbuffered streams for content-types like `multipart/octet-stream`.
fix
Be aware of buffering behavior differences when targeting older browsers. Implement client-side buffering or progressive rendering if necessary for older browser compatibility, or ensure modern browser targets for true streaming.
affects: <=1.7.0
deprecated`http-browserify` is primarily designed for the Browserify ecosystem. While still functional, newer bundling tools like Webpack and Rollup often provide their own strategies for polyfilling Node.js APIs or encourage explicit browser-native APIs (e.g., `fetch` or `XMLHttpRequest`).
fix
For new projects, consider using `fetch` or `XMLHttpRequest` directly for HTTP requests, or leverage modern bundler features for polyfilling if Node.js-like APIs are preferred. For existing Browserify projects, continue using `http-browserify`.
affects: >=1.0.0
gotchaThe `http.request` `opts.host` and `opts.port` default to `window.location.host` and `window.location.port` respectively. This means requests are implicitly made to the same origin unless explicitly specified.
fix
Always explicitly set `opts.host` and `opts.port` (and `opts.protocol` if necessary) when making requests to a different origin to avoid unexpected same-origin requests. Be mindful of CORS implications for cross-origin requests.
affects: >=1.0.0
Errors
Common errors & fixes
Uncaught ReferenceError: require is not defined
`require('http')` is being called in a browser environment without prior bundling by Browserify.
fix
Ensure your JavaScript code is bundled using Browserify. Run `browserify your-entry-file.js -o bundle.js` and include `bundle.js` in your HTML. `http-browserify` only works when processed by Browserify.
TypeError: Cannot read properties of undefined (reading 'on') when calling res.on('data')
The `res` (response) object from `http.get` or `http.request` might not be fully initialized or an error occurred before the response stream was ready.
fix
Ensure the callback passed to `http.get` or `http.request` properly receives the `res` object. Check for network errors or server issues that might prevent a valid HTTP response, or handle errors on the `req` object itself.
Upgrade
Version history
1.7.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
http-browserify — npm install http-browserify · libregistry