0

I work for a company that has strict IT policy. I work behind a proxy and i mostly use Proxifier or sometimes set proxy in Windows setting.
I am developing API with Node.js and at first just to test I created a simple route that makes a call to 'https://jsonplaceholder.typicode.com/posts'. Whenever I test my route in Postman, I get error "Error: self signed certificate in certificate chain" in command prompt where node js is running.
But when I test 'https://jsonplaceholder.typicode.com/posts' directly in Postman, it works.
here is the simple code I wrote to test:

exports.testing = async(req, res, next) => {
    try {
        const data = await axios.get("https://jsonplaceholder.typicode.com/posts")
        console.log({"Data": data.data})
    }catch(err){
        console.error({"ERROR": err});
    }
}

What I have tried:
npm config set strict-ssl false --global (didn't help, i assume this is for downloading npm packages)
npm config set cafile /path/to/your/cert.pem --global (didn't help)
set NODE_TLS_REJECT_UNAUTHORIZED=0 (didn't help)
set NODE_EXTRA_CA_CERTS=/path/to/your/cert.pem (didn't help)

P.S.
When I use mobile data, it works perfectly

1 Answers1

0
httpsAgent: new https.Agent({
    rejectUnauthorized: false
})

Not a perfect solution, but ok for development env

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 28 '21 at 10:08