To add custom certificate authority (CA) to Node.js, we call the options.ca.push method.
For instance, we write
const trustedCa = [
"/etc/pki/tls/certs/ca-bundle.crt",
"/path/to/custom/cert.crt",
];
https.globalAgent.options.ca = [];
for (const ca of trustedCa) {
https.globalAgent.options.ca.push(fs.readFileSync(ca));
}
to loop through each trusrtedCa path with a for-of loop.
In it, we call https.globalAgent.options.ca.push with the file read from readFileSync to add the certificate file into the array with push.