API Testing error

Error: self-signed certificate in certificate chain

Node refused the HTTPS connection because a certificate in the chain was signed by a CA it doesn't trust, usually a corporate proxy or an internal company CA.

Published

Why this happens

How to fix it

  1. Point Node at the extra CA with `NODE_EXTRA_CA_CERTS=/path/to/company-ca.pem`
  2. Or, on Node 23.8+ (and 22.15+), use `--use-system-ca` so Node trusts the same CAs as the operating system
  3. Avoid `NODE_TLS_REJECT_UNAUTHORIZED=0`. It turns off certificate checks for every request in the process, and it tends to get copied into CI and forgotten

Example


              # Trust the company CA for this test run only
NODE_EXTRA_CA_CERTS=./certs/company-root-ca.pem npm run test:api