2

I am trying to set extra CAs for my nodejs project, I tried using " set NODE_EXTRA_CA_CERTS={directorty}/ca.pem" but the nodejs project still cannot pick up the set env variable.

How can set this variable?

WakandaKing
  • 51
  • 1
  • 1
  • 3
  • In your case, are you on Windows? Possible duplicate questions exist. But was looking for documentation myself. Finally found it hidden between a number of sites and SO questions. https://nodejs.org/api/cli.html#node_extra_ca_certsfile Make sure you dont set CA. And set the environmentvalue before starting nodejs. Other SO q: https://stackoverflow.com/questions/23788564/npm-add-root-ca/56239954#56239954 – Michael Mar 03 '22 at 20:42

1 Answers1

4

Used the answer from https://stackoverflow.com/a/56239954/3700823 myself.

On windows you should backslashes instead of slashes. And make sure you use the full path (like set NODE_EXTRA_CA_CERTS=C:\stuffed\subfolder\thefile.pem). Though some mention relative path (like set NODE_EXTRA_CA_CERTS=.\subfolder\thefile.pem) should work as well, not tested myself. Maybe that's only valid for *nix.

Then either try restart node.exe, or the machine to make sure node.exe starts using the environment variable. For me it began to work after rebooting.

As the nodejs documentation mentions, nodejs should warn you once about any issue. Check the official documentation: https://nodejs.org/api/cli.html#node_extra_ca_certsfile

Michael
  • 344
  • 5
  • 17