
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
agent-base
Advanced tools
http.Agent instanceThis module is a thin wrapper around the base http.Agent class.
It provides an abstract class that must define a connect() function,
which is responsible for creating the underlying socket that the HTTP
client requests will use.
The connect() function may return an arbitrary Duplex stream, or
another http.Agent instance to delegate the request to, and may be
asynchronous (by defining an async function).
Instances of this agent can be used with the http and https
modules. To differentiate, the options parameter in the connect()
function includes a secureEndpoint property, which can be checked
to determine what type of socket should be returned.
Here are some more interesting uses of agent-base.
Send a pull request to list yours!
http-proxy-agent: An HTTP(s) proxy http.Agent implementation for HTTP endpointshttps-proxy-agent: An HTTP(s) proxy http.Agent implementation for HTTPS endpointspac-proxy-agent: A PAC file proxy http.Agent implementation for HTTP and HTTPSsocks-proxy-agent: A SOCKS proxy http.Agent implementation for HTTP and HTTPSHere's a minimal example that creates a new net.Socket or tls.Socket
based on the secureEndpoint property. This agent can be used with both
the http and https modules.
import * as net from 'net';
import * as tls from 'tls';
import * as http from 'http';
import { Agent } from 'agent-base';
class MyAgent extends Agent {
connect(req, opts) {
// `secureEndpoint` is true when using the "https" module
if (opts.secureEndpoint) {
return tls.connect(opts);
} else {
return net.connect(opts);
}
}
});
// Keep alive enabled means that `connect()` will only be
// invoked when a new connection needs to be created
const agent = new MyAgent({ keepAlive: true });
// Pass the `agent` option when creating the HTTP request
http.get('http://nodejs.org/api/', { agent }, (res) => {
console.log('"response" event!', res.headers);
res.pipe(process.stdout);
});
The http-proxy-agent package provides an HTTP Agent implementation that connects to a specified HTTP proxy server. It is similar to agent-base in that it allows you to customize the behavior of HTTP requests, but it is specifically designed for proxying.
Similar to http-proxy-agent, https-proxy-agent is an HTTPS Agent implementation for proxying HTTPS requests. It provides similar functionality to agent-base but is tailored for HTTPS connections through a proxy server.
The socks-proxy-agent package is an HTTP Agent that connects to a SOCKS proxy server. It is another example of a package that extends the functionality of the core HTTP Agent, similar to agent-base, but with a focus on SOCKS proxy support.
FAQs
Turn a function into an `http.Agent` instance
The npm package agent-base receives a total of 39,691,160 weekly downloads. As such, agent-base popularity was classified as popular.
We found that agent-base demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.