dev-resources.site
for different kinds of informations.
HTTP timeout with Axios
Published at
9/25/2024
Categories
javascript
node
api
axios
Author
Željko Šević
Setting up a timeout for HTTP requests can prevent the connection from hanging forever, waiting for the response. It can be set on the client side to improve user experience, and on the server side to improve inter-service communication.
axios
package provides a timeout
parameter for this functionality.
const HTTP_TIMEOUT = 3000;
const URL = 'https://www.google.com:81';
(async () => {
try {
await axios(URL, {
timeout: HTTP_TIMEOUT,
});
} catch (error) {
console.error('Request timed out', error.cause);
}
})();
Use this snippet also to simulate aborted requests.
Course
Build your SaaS in 2 weeks - Start Now
Articles
12 articles in total
HTTP timeout with Axios
currently reading
RabbitMQ container with Docker Compose
read article
Simulating keyboard typing with JavaScript
read article
Profiling Node.js apps with Chrome DevTools profiler
read article
Load and stress testing with k6
read article
Node Version Manager (nvm) overview
read article
Debugging Node.js apps with Chrome DevTools debugger
read article
Sending e-mails with Sendgrid
read article
MongoDB containers with Docker Compose
read article
Web scraping with cheerio
read article
Integration with GitHub GraphQL API
read article
Web scraping with jsdom
read article
Featured ones: