<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: BTP NodeJS Express API with PostgreSQL Database Connection in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaa-p/12576143#M4715899</link>
    <description>&lt;P&gt;thank you...&lt;/P&gt;</description>
    <pubDate>Fri, 17 Feb 2023 10:07:30 GMT</pubDate>
    <dc:creator>vbalko-claimate</dc:creator>
    <dc:date>2023-02-17T10:07:30Z</dc:date>
    <item>
      <title>BTP NodeJS Express API with PostgreSQL Database Connection</title>
      <link>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaq-p/12576139</link>
      <description>&lt;P&gt;I have exhausted my attempts to connect to my PostgreSQL Hyperscaler instance in BTP and thought I'd reach out to the community for help since I wasn't able to find an answer yet. I have a working node express api app that leverages a local postgreSQL database and returns data. But when I deploy to BTP I cannot connect to my PostgreSQL Hyperscaler instance - I get a 502 Bad Gateway response.&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;My question is what I do to connect to the database once I deploy the app to BTP? Can someone indicate what I'm doing wrong in my connection code?&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
  &lt;OL&gt;
   &lt;LI&gt;I have a PostgreSQL Hyperscaler instance running.&lt;/LI&gt;
   &lt;LI&gt;I have the node app running in BTP.&lt;/LI&gt;
   &lt;LI&gt;I have enabled ssh for the application.&lt;/LI&gt;
   &lt;LI&gt;I have a Bind Service.&lt;/LI&gt;
  &lt;/OL&gt;
  &lt;P&gt;Here is the Bind Service (some information removed):&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;{
	"username": "9a5121579182",
	"password": "XXXXXXXXXX",
	"hostname": "postgres-fdb76d9f-e770-4d87-8cff-c105aa990222.cqryblsdrbcs.us-east-1.rds.amazonaws.com",
	"dbname": "XXXXXXXXXX",
	"port": "3959",
	"uri": "postgres://9a5121579182:XXXXXXXXXX@postgres-fdb76d9f-e770-4d87-8cff-c105aa990222.cqryblsdrbcs.us-east-1.rds.amazonaws.com:3959/XXXXXXXXXX",
	"sslcert": "-----BEGIN CERTIFICATE-----REMOVED FOR EXAMPLE-----END CERTIFICATE-----",
	"sslrootcert": "-----BEGIN CERTIFICATE-----REMOVED FOR EXAMPLE-----END CERTIFICATE-----"
}&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Here is my connection in my &lt;STRONG&gt;queries.js&lt;/STRONG&gt; file .env populated with the Bind Service information from above.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;PRE&gt;&lt;CODE&gt;const Pool = require('pg').Pool
const pool = new Pool({ 
  
  user: `${process.env.DB_USER}`,
  host: `${process.env.DB_HOST}`,
  database: `${process.env.DB_DATABASE}`,
  password: `${process.env.DB_PASSWORD}`,
  port: `${process.env.DB_PORT}`

})&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Here is my VCAP_SERVICES results:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;VCAP_SERVICES: {
  "postgresql-db": [
    {
      "binding_guid": "4d953482-131d-4729-aa3a-812ef796da51",
      "binding_name": null,
      "credentials": {
        "dbname": "XXXXXXXXXX",
        "hostname": "postgres-fdb76d9f-e770-4d87-8cff-c105aa990222.cqryblsdrbcs.us-east-1.rds.amazonaws.com",
        "password": "XXXXXXXXXX",
        "port": "3959",
        "sslcert": "-----BEGIN CERTIFICATE-----REMOVED FOR EXAMPLE-----END CERTIFICATE-----",
	"sslrootcert": "-----BEGIN CERTIFICATE-----REMOVED FOR EXAMPLE-----END CERTIFICATE-----"
        "uri": "postgres://9a5121579182:XXXXXXXXXX@postgres-fdb76d9f-e770-4d87-8cff-c105aa990222.cqryblsdrbcs.us-east-1.rds.amazonaws.com:3959/XXXXXXXXXX",
        "username": "9a5121579182"
      },
      "instance_guid": "fdb76d9f-e770-4d87-8cff-c105aa990222",
      "instance_name": "XXXXXXXXXX",
      "label": "postgresql-db",
      "name": "XXXXXXXXXX",
      "plan": "trial",
      "provider": null,
      "syslog_drain_url": null,
      "tags": [
        "relational",
        "database"
      ],
      "volume_mounts": []
    }
  ]
}&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Jul 2022 18:14:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaq-p/12576139</guid>
      <dc:creator>chad_fraser</dc:creator>
      <dc:date>2022-07-21T18:14:15Z</dc:date>
    </item>
    <item>
      <title>Re: BTP NodeJS Express API with PostgreSQL Database Connection</title>
      <link>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaa-p/12576140#M4715896</link>
      <description>&lt;P&gt;Well I solved the issue. What I was missing was the ssl key in the client config. The connection was failing because the connection requires ssl. Here is the query code.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;const pg = require('pg');
&lt;BR /&gt;
pool = new pg.Client({
    host: db_hostname,
    port: db_port,
    database: db_database,
    user: db_username,
    password: db_password,
    ssl: {
        require: db_ssl,
        rejectUnauthorized : false
    }
  });

pool.connect();

const getData = (request, response) =&amp;gt; {
  pool.query('SELECT * FROM some_table ORDER BY id ASC', (error, results) =&amp;gt; {
    if (error) {
      throw error
    }
    response.status(200).json(results.rows)
  })
}

module.exports = {
    getData
  }&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jul 2022 17:57:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaa-p/12576140#M4715896</guid>
      <dc:creator>chad_fraser</dc:creator>
      <dc:date>2022-07-28T17:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: BTP NodeJS Express API with PostgreSQL Database Connection</title>
      <link>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaa-p/12576141#M4715897</link>
      <description>&lt;P&gt;Hello  &lt;SPAN class="mention-scrubbed"&gt;chad.fraser&lt;/SPAN&gt; ,&lt;/P&gt;&lt;P&gt;thanks for sharing solution.&lt;/P&gt;&lt;P&gt;What is&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ssl: {&lt;BR /&gt;require: db_ssl&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;statement? I couldnt find that in docu, what its used for? and What did you put into db_ssl - just true/false or cert from sslcert VCAP?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 14:04:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaa-p/12576141#M4715897</guid>
      <dc:creator>vbalko-claimate</dc:creator>
      <dc:date>2023-02-16T14:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: BTP NodeJS Express API with PostgreSQL Database Connection</title>
      <link>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaa-p/12576142#M4715898</link>
      <description>&lt;P&gt;The "required" property is a boolean and be set to "true".&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ssl: {
        require: true,
        rejectUnauthorized : false
      }&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Feb 2023 16:46:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaa-p/12576142#M4715898</guid>
      <dc:creator>chad_fraser</dc:creator>
      <dc:date>2023-02-16T16:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: BTP NodeJS Express API with PostgreSQL Database Connection</title>
      <link>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaa-p/12576143#M4715899</link>
      <description>&lt;P&gt;thank you...&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 10:07:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaa-p/12576143#M4715899</guid>
      <dc:creator>vbalko-claimate</dc:creator>
      <dc:date>2023-02-17T10:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: BTP NodeJS Express API with PostgreSQL Database Conne...</title>
      <link>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaa-p/14201258#M4924630</link>
      <description>&lt;P&gt;I got the solution of NestJS and TypeORM BTP postgres&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import { DynamicModule, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({})
export class DatabaseModuleBTP {
  static async forRoot(): Promise&amp;lt;DynamicModule&amp;gt; {
    const creds = JSON.parse(process.env.VCAP_SERVICES || '{}')["postgresql-db"][0].credentials;
    await new Promise(resolve =&amp;gt; setTimeout(resolve, 1000));
    return {
      module: DatabaseModuleBTP,
      imports: [
        TypeOrmModule.forRoot({
          type: 'postgres',
          host: creds.hostname,
          port: Number(creds.port),
          username: creds.username,
          password: creds.password,
          database: creds.dbname,
          ssl: {
            rejectUnauthorized: true,
            ca: creds.sslrootcert.replace(/\\n/g, '\n'),
            cert: creds.sslcert.replace(/\\n/g, '\n'),
          },

          entities: [__dirname + '/../**/*.entity{.ts,.js}'],
          synchronize: true,
          logging: ['query', 'error', 'log', 'warn', 'info'],
          autoLoadEntities: true,
        }),
      ],
    };
  }
}​&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 31 Aug 2025 03:11:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/btp-nodejs-express-api-with-postgresql-database-connection/qaa-p/14201258#M4924630</guid>
      <dc:creator>Kuldip_Botre81</dc:creator>
      <dc:date>2025-08-31T03:11:30Z</dc:date>
    </item>
  </channel>
</rss>

