Node.js error with SSL UNABLE_TO_VERIFY_LEAF_SIGNATURE Node.js error with SSL UNABLE_TO_VERIFY_LEAF_SIGNATURE windows windows

Node.js error with SSL UNABLE_TO_VERIFY_LEAF_SIGNATURE


I'm using a package called "superagent" and getting the same error. After trying several potential fixes, I came across this one that works for me 100% of the time:

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

There's no need to do any requires or whatever : just add this to your code before your network calls and you're good to go.


The SSL certificate used by the server in your example is probably not fully trusted by the WebSocket client so NodeJS is throwing an error in its network library on the client-side.

You need to set rejectUnauthorized to false (this is an option that most high-level network libraries will allow you to set via an option that gets passed to the lower level NodeJS networking library).

I skimmed the ws module source code and looks like you should try this:

var ws = new WebSocket('wss://localhost:8080', null, {rejectUnauthorized: false});

NOTE: rejectUnauthorized should only be false during testing/development. Production applications should always use rejectUnauthorized: true for full security.


If you do not want to disable your security. Add ca: [cert] option in http /socket client options.Where cert is Certificate of server you are connecting to or CA of the server you are connecting to.