javascript - what is ca file path for inclusion in nodejs httpAgent

The folder structure is like this, and the root of the client and server folders is itself.

app
 |- client 
 |- server 

The request header contains the httpAgent property and the nodejs server sent an import request to a website that requires a public certificate, but the following error appears

  cause: Error: unable to get local issuer certificate
      at TLSSocket.onConnectSecure (node:_tls_wrap:1530:34)
      at TLSSocket.emit (node:events:520:28)
      at TLSSocket._finishInit (node:_tls_wrap:944:8)
      at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:725:12) {
    code: 'UNABLE_TO_GET_ISSUER_CERT_LOCALLY'
  }

The homepage that receives my request is made with php.

> npm config set cafile "openSSL.pem"

> npm config ls -l

> ca = null 
  ; cafile = null ; overridden by user
  cafile = "/Users/user/app/server/AlphaSSL CA - SHA256 - G2.pem"
const httpsAgent = https.Agent({
  ca: "/AlphaSSL CA - SHA256 - G2",
  keepAlive: true,
});
module.exports = async (req, res) => {
  const mealsPage = await axios({
    method: "get",
    baseURL: "baseURL",
    url: "url",
    withCredentials: true,
    httpsAgent: httpsAgent,
  });

+++ not occur error

const httpsAgent = https.Agent({
  ca: fs.readFileSync("GlobalSign Root CA.pem"),
  keepAlive: true,
});

why occur error? cause: Error: unable to get issuer certificate

const httpsAgent = https.Agent({
  ca: fs.readFileSync("AlphaSSL CA - SHA256 - G2.pem"),
  keepAlive: true,
});

page root certificate is GlobalSign Root CA.pem, middle certificate is AlphaSSL CA - SHA256 - G2.pem.

Answer

Solution:

page root certificate is GlobalSign Root CA.pem, middle certificate is AlphaSSL CA - SHA256 - G2.pem.

You answered your own question. AlphaSSL CA is just an intermediate certificate, it is not the root certificate.

Maybe it's because the intermediate certificate is not marked as a CA, therefor it can't be used as a CA.

Source