Categories
JavaScript Answers

How to modify the Node.js request default timeout time?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *