Recently I came across the same error in Node connecting to external system,where i had the certificate in right path and validity of certificate was right.But still i was getting the mentioned error:UNABLE_TO_VERIFY_LEAF_SIGNATURE | unable to verify the first certificate
Cause of issue in my case: Certificate which was provided by the external system team was exported from the browser ,though it is valid still we were getting the error.tried installing the certificate on both current User profile and Local Machine profile(didn'worked) ,tried setting NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' ,tried setting NODE_EXTRA_CA_CERTS with cert path this too didn't worked. Finally in some documentation i have found that when ever the server to server connection is established it expects the Chain of certificates from source to destination. which i exported using below steps(this is the solution which worked in my case) 1)logged in the destination server URL HTTPS site > 2)Hit right click on inspect 3)goto Security/privacy tab 4)find certificate identity and Export Option> 5)here is the key step while exporting select the option of chain Certificate Export(this should allow you to verify the leaf of certificate)