Sometimes, we want to modify the Node.js request default timeout time.
In this article, we’ll look at how to modify the Node.js request default timeout time.
How to modify the Node.js request default timeout time?
To modify the Node.js request default timeout time, we can set the timeout
option when we call request
.
For instance, we write
const options = {
url: 'http://example.com',
timeout: 120000
}
request(options, (err, resp, body) => {
//...
});
to call request
with options
.
We set the timeout
option to set the request timeout to 120000 milliseconds.
Conclusion
To modify the Node.js request default timeout time, we can set the timeout
option when we call request
.