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.