I have a Docker container running this image on my machine (it's a SOCKS proxy server) and I have exposed the needed ports needed for it to work. And when I run curl -x socks5://localhost:40000 https://ip.me
on my machine, the requests goes through fine and everything works. But when I try to send a request from node using the proxy agent, it doesn't work. Here is my code:
const fetch = require('node-fetch')
const { SocksProxyAgent } = require('socks-proxy-agent')
const req = await fetch(`https://google.com`, {
agent: new SocksProxyAgent(`socks5://localhost:40000`)
})
console.log(req.ok)
console.log(req.status)
Here is my error:
/home/______/______/node_modules/node-fetch/lib/index.js:1376
reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err));
^
FetchError: request to https://google.com/ failed, reason: Socket closed
at ClientRequest.<anonymous> (/home/______/______/node_modules/node-fetch/lib/index.js:1376:11)
at ClientRequest.emit (node:events:390:28)
at onerror (/home/______/______/node_modules/socks-proxy-agent/node_modules/agent-base/dist/src/index.js:117:21)
at callbackError (/home/______/______/node_modules/socks-proxy-agent/node_modules/agent-base/dist/src/index.js:136:17) {
type: 'system',
errno: undefined,
code: undefined
}
Node.js v17.0.0
I'm not sure why this is happening. Can anyone try to help?