Timeout Configuration in JavaScript
From the Axios cheat sheet · Request Cancellation & Timeout · verified Jul 2026
Timeout Configuration
Set connection and response timeouts to prevent hanging
javascript
// Request timeout (5 seconds)
const response = await axios.get('/api/data', {
timeout: 5000
});
// Different timeouts per instance
const api = axios.create({
baseURL: 'https://api.example.com',
timeout: 10000 // 10 seconds default
});
// Override instance timeout
const quick = await api.get('/fast', { timeout: 2000 });
const slow = await api.get('/slow', { timeout: 30000 });✅ timeout applies to entire request - both connection and response
💡 Implement exponential backoff when retrying timeout errors
🔍 Use error.code === "ECONNABORTED" to detect timeout errors
⚡ Set different timeouts for fast/slow endpoints to optimize UX
timeoutretrybackoffperformance