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.
Socks5Agent
✓ import Socks5Agent from 'axios-socks5-agent';
✗ const { Socks5Agent } = require('axios-socks5-agent');
Package uses a single default export. CommonJS require must assign the whole module to a variable; named destructuring does not match the export.
httpAgent
✓ const agent = Socks5Agent({ host, port }); // then use agent.httpAgent
✗ const { httpAgent } = require('axios-socks5-agent');
httpAgent and httpsAgent are properties of the object returned by calling Socks5Agent(options). They are not direct exports.
httpsAgent
✓ const agent = Socks5Agent({ host, port }); // then use agent.httpsAgent
✗ const httpsAgent = Socks5Agent.httpsAgent;
Same as httpAgent; must invoke the function with options to get the agents.
Creates SOCKS5 agents with auth and custom agent options, then uses them in an Axios GET request.
import axios from 'axios';
import Socks5Agent from 'axios-socks5-agent';
const agent = Socks5Agent({
host: '127.0.0.1',
port: 9050,
agentOptions: { keepAlive: true },
});
async function main() {
try {
const res = await axios.get('http://wtfismyip.com/json', {
httpAgent: agent.httpAgent,
httpsAgent: agent.httpsAgent,
});
console.log(res.data);
} catch (err) {
console.error(err);
}
}
main();
Errors
Common errors & fixes
Cannot read property 'httpAgent' of undefined
Socks5Agent called without options or returned undefined.
fixEnsure you call Socks5Agent(options) and capture the return value.
TypeError: Socks5Agent is not a function
Incorrect import (named import) when the module uses default export.
fixUse import Socks5Agent from 'axios-socks5-agent' (no curly braces).
Audit
Dependencies
socks5-http-clientrequiredProvides the underlying SOCKS5 HTTP agent implementation
socks5-https-clientrequiredProvides the underlying SOCKS5 HTTPS agent implementation
axiosoptionalPeer dependency; the agents are designed to be used with Axios