https-proxy-agent is not working in my node project

369 Views Asked by At

this is very small app by which i am trying to download files from s3 bucket, running this behind corporate proxy config. I am using 'https-proxy-agent' to setup proxy in the api call but app is giving error when i am trying to start node app. I tried some other ways to use proxyagent but no luck.

getting the error below.
agent: new ProxyAgent(proxyUrl).
^ TypeError: ProxyAgent is not a constructor

below is my code

const AWS = require('aws-sdk');
const fs = require('fs');
const path = require('path');
const ProxyAgent = require('https-proxy-agent')

const app = express();
const port = 3003;
const proxyUrl = 'http://pac.prod.proxy.cargill.com:4200/proxy.pac'

// Set your AWS credentials and region
AWS.config.update({
    secretAccessKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    accessKeyId: 'xxxxxxxxxxxxxxxxxxxx',
    region: 'us-east-1',
    httpOptions:{
      agent: new ProxyAgent(proxyUrl)
    }
});

// Initialize S3
const s3 = new AWS.S3();```


1

There are 1 best solutions below

0
On BEST ANSWER

The docs for the module say to import it as

import { HttpsProxyAgent } from 'https-proxy-agent';

, that is, it's not the default export.

That would translate to

const { HttpsProxyAgent } = require('https-proxy-agent');