Here is my connection code :

        this.connection = mysql.createConnection({
            host: '',
            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

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.

Submit an Answer
3 answers
ssl: {
                ca: fs.readFileSync(__dirname + '/ca-certificate.crt'),

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

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

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.