Categories
JavaScript Answers

How to fix ‘Error: unable to verify the first certificate’ in Node.js?

Spread the love

Sometimes, we want to fix ‘Error: unable to verify the first certificate’ in Node.js.

In this article, we’ll look at how to fix ‘Error: unable to verify the first certificate’ in Node.js.

How to fix ‘Error: unable to verify the first certificate’ in Node.js?

To fix ‘Error: unable to verify the first certificate’ in Node.js, we should set the appropriate root certificate.

For instance, we write

require('https').globalAgent.options.ca = require('ssl-root-cas/latest').create();

to call require with 'ssl-root-cas/latest' to require the root certificate.

Then we can set that has the value of the require('https').globalAgent.options.ca property so https would use the required root certificate.

Conclusion

To fix ‘Error: unable to verify the first certificate’ in Node.js, we should set the appropriate root certificate.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *