Report this

What is the reason for this report?

How to use ${_self.CA_CERT} in when accessing Postgres DB from Nodejs app?

Posted on February 1, 2023

Goal is to avoid Error: self signed certificate in certificate chain or disabling it by setting Node env.

I do not think copying content from ${_self.CA_CERT} env to file and uploading it to repository and referring it as file approach sounds safe. There is support page describing saving it using script and referring it at runtime, I tried it like

DATABASE_URL=${self.DATABASE_URL}&sslrootcert=/workspace/ca_cert.cert

even tried setting NODE_EXTRA_CA_CERTS

I am using Postgraphile as middleware in my case, trying to connect to dev database.



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 was able to fix this in Postgraphile by using Pool from pg

export const pool = new Pool({
    user: process.env.DB_USERNAME,
    host: process.env.DB_HOSTNAME,
    database: process.env.DATABASE,
    password: process.env.DB_PASSWORD,
    port: Number(process.env.DB_PORT),
    ssl: {
       rejectUnauthorized: true,
       ca: process.env.CA_CERT,
    },
})

and passing pool object postgraphile

const middleware = postgraphile(db, schemas, options)

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.