Question

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

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.


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.

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)

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel