Question

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

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

Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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

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 :/