I use azure postgres, so when I disable SSL it works fine but I want SSL connection enabled and when I enable from azure
and then when I start my application ERROR: SSL connection is required. Please specify SSL options and retry
This error occurs multiple time
where in docs of azure Azure Docs for SSL . here is my connection string
connection: {
database: process.env.POSTGRES_DATABASE || 'postgres',
port: process.env.POSTGRES_PORT || 5432,
user: process.env.POSTGRES_USER || 'my@-username',
host: process.env.POSTGRES_HOST || 'postgres.db.postgres.database.azure.com',
password: process.env.POSTGRES_PASSWORD || 'postpass',
sslmode: 'require',
}
as per azure docs i specify that sslmode:require
but its not working
is anyone face the same error and got the solution then let me know, I stuck into this error from last 5 days.
Regarding the issue, please refer to the following steps
Download the SSL certificate. For more details, please refer to here
Code
const pg = require("pg");
const fs = require("fs");
const config = {
host: "<>.postgres.database.azure.com",
user: "<>",
password: "<>",
database: "postgres",
port: 5432,
ssl: {
cert: fs.readFileSync("<the cert path>"),
rejectUnauthorized: true,
},
};
const client = new pg.Client(config);
client.connect((err) => {
if (err) throw err;
else {
console.log("success");
}
});
const query = "SELECT * FROM inventory;";
client
.query(query)
.then((res) => {
const rows = res.rows;
console.log(`Read: ${JSON.stringify(rows)}`);
process.exit();
})
.catch((err) => {
console.log(err);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With