Report this

What is the reason for this report?

Can't connect via NodeJS - Error: self signed certificate in certificate chain

Posted on December 9, 2019

Here is my connection code :

        this.connection = mysql.createConnection({
            host: 'xxxx.db.ondigitalocean.com',
            user: 'doadmin',
            port: 25060,
            password: 'xxxx',
            dialect: 'mysql',
            force: true,
            ssl: {
                cert: fs.readFileSync(__dirname + '/ca-certificate.crt'),
            }

        });

Here is the error im getting

(node:5676) UnhandledPromiseRejectionWarning: Error: self signed certificate in certificate chain


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I’m experiencing the exact same issue. The certificate provided by DO doesn’t make a connection possible from my local computer to the managed DB. I’d really appreciate some input on how to use it within a node.js application and one of the available mysql drivers.

So far I couldn’t find any solutions online, which unfortunately prevents me from actually using DO :/

ssl: {
                ca: fs.readFileSync(__dirname + '/ca-certificate.crt'),
            }

Change cert attribute to ca You can even add rejectUnauthorized: true

Hi @nickynick,

Usually when experiencing this issue is when you are using a SELF SIGNED certificate, is that correct?

If that’s the case, add NODE_TLS_REJECT_UNAUTHORIZED='0' as an environment variable wherever you are running node or running node directly with NODE_TLS_REJECT_UNAUTHORIZED='0' node app.js

This instructs Node to allow untrusted certificates (untrusted = not verified by a certificate authority)

I would not recommend setting this environment variable in production as your application would not be trusted by users. You can use free Let’s Encrypt certificates.

Regards, KDSys

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.