var fetch = require('node-fetch');
var HttpsProxyAgent = require('https-proxy-agent');
var proxy = 'http://192.40.242.55:53281';
var options = {
timeout: 5000,
agent: new HttpsProxyAgent(proxy),
};
var time = +new Date();
fetch('http://httpbin.org/ip', options)
.then(res => res.json())
.then(json => {
console.log(json);
console.log('Time: ' + (+new Date() - time));
})
.catch(err => {
console.error(err);
console.log('Time: ' + (+new Date() - time));
});
https-proxy-agent creating new HttpsProxyAgent instance: Url { protocol: 'http:', slashes: true, auth: null, host: '192.40.242.55:53281', port: '53281', hostname: '192.40.242.55', hash: null, search: null, query: null, pathname: '/', path: '/', href: 'http://192.40.242.55:53281/' } +0ms
{ FetchError: request to http://httpbin.org/ip failed, reason: read ECONNRESET
at ClientRequest.<anonymous> (/Users/rodolfo/Downloads/proxies/node_modules/node-fetch/lib/index.js:1393:11)
at emitOne (events.js:116:13)
at ClientRequest.emit (events.js:211:7)
at onerror (/Users/rodolfo/Downloads/proxies/node_modules/agent-base/index.js:101:9)
at callbackError (/Users/rodolfo/Downloads/proxies/node_modules/agent-base/index.js:123:5)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
message: 'request to http://httpbin.org/ip failed, reason: read ECONNRESET',
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET' }
Time: 48375
The request took 48375 milliseconds instead of 5000 of my timeout.
I tested the above code with the http-proxy-agent
library and works perfectly.