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.

http-networkingweb-framework
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

This package is designed for CommonJS environments and Browserify bundling. It directly shims Node.js's 'http' module.

const http = require('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.

var bundle = browserify({ require : { http : 'http-browserify' } });

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 footguns
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`.
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`).
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.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources