Modify NodeJS Request Default Timeout

Posted on April 15, 2020 at 9:37 am

You can modify the default request timeout like this:

var options = {
    url:  'https://www.google.com/',
    timeout: 120000
}
 
request(options, function(err, resp, body) {});

Details of the param timeout can be found here:

https://github.com/request/request#user-content-requestoptions-callback

timeout - integer containing number of milliseconds, controls two timeouts.
 
Read timeout: Time to wait for a server to send response headers (and start the response body) before aborting the request.
Connection timeout: Sets the socket to timeout after timeout milliseconds of inactivity. Note that increasing the timeout beyond the OS-wide TCP connection timeout will not have any effect (the default in Linux can be anywhere from 20-120 seconds)

Receive updates via email

Other Posts

Updated Posts