Skip to content

Instantly share code, notes, and snippets.

@dobeerman
Forked from ccnokes/axios-instance-config.js
Created February 11, 2018 01:24
Show Gist options
  • Select an option

  • Save dobeerman/4f7899a66c2925d63e7cbd7e34dd3d05 to your computer and use it in GitHub Desktop.

Select an option

Save dobeerman/4f7899a66c2925d63e7cbd7e34dd3d05 to your computer and use it in GitHub Desktop.
Good default configuration for axios in node.js
const axios = require('axios');
const http = require('http');
const https = require('https');
module.exports = axios.create({
//60 sec timeout
timeout: 60000,
//keepAlive pools and reuses TCP connections, so it's faster
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true }),
//follow up to 10 HTTP 3xx redirects
maxRedirects: 10,
//cap the maximum content length we'll accept to 50MBs, just in case
maxContentLength: 50 * 1000 * 1000
});
//optionally add interceptors here...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment