Proxy Port logo
How-to Guides > How to set up a proxy for Axios

How to set up a proxy for Axios

This article will be helpful if you are struggling with this error:
cause: Error: write EPROTO 139802847135616:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:

      at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:98:16) {
    errno: -71,
    code: 'EPROTO'
            
        
Straight to the point.
To set a proxy for Axios and not shoot yourself you need to do the following:
  1. Install https-proxy-agent package

    npm i https-proxy-agent
            
  2. Set proxy with httpsAgent
const axios = require('axios');
const HttpsProxyAgent = require('https-proxy-agent');

const url = "https://example.com";
const config = {
    httpsAgent: new HttpsProxyAgent('http://yourproxyserver.com:8080'),
};

(async() => {
    let response = await axios.get(url, config);
    console.log(response?.data);
})();


            
        
Proxy for scraping
More