Categories
JavaScript Answers

How to fix Node.js request CERT_HAS_EXPIRED error?

Spread the love

To fix Node.js request CERT_HAS_EXPIRED error, we set the rejectUnauthorized property to false.

For instance, we write

const request = require("request");

const agentOptions = {
  host: "www.example.com",
  port: "443",
  path: "/",
  rejectUnauthorized: false,
};
const agent = new https.Agent(agentOptions);

request(
  {
    url: "https://www.example.com/api/endpoint",
    method: "GET",
    agent,
  },
  (err, resp, body) => {
    // ...
  }
);

to call request with the agent object we by calling Agent with the agentOptions to make the request.

We set rejectUnauthorized to skip checking for invalid certificate.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *