I am sending a request like https GET to an external API.
First I created an https agent as shown below:
import https from 'https'; const KeepAliveAgent = new https.Agent( { keepAlive: true } );
then set the query parameters as shown below:
let options = { url: 'externalapiurl', method: "GET", qs: queryString, agent: KeepAliveAgent };
I just mentioned example strings for url and qs, in the original request I use the actual api url and querystring, then I will send the request as shown below:
console.time( "requestTime" ); request( options, ( err, response, body ) => { if ( err ) { logger.warn( err.message ); } console.timeEnd( "requestTime" ); });
This works fine, but I print the time taken to answer above, and this time a lot more when I send a request for a proxy server, when I do not use a proxy server that takes less than half a second, but taking a proxy server about 3 seconds, so it seems that "keep alive" does not work for the proxy, how to do it? I tried the same request using the https-proxy-agent node module, but the problem still persists, appreciate any help.
nodercoder
source share