Reputation: 11
I have a node js image that needs to connect to a postgreSQL db currently hosted on the aws rds.
The bitnami docs describe how to connect to an oracle database, here https://docs.bitnami.com/aws/infrastructure/nodejs/#how-to-connect-your-nodejs-application-to-an-oracle-database, but I cannot find ANY literature or anything on an analogous method to connect to a postgres db.
I assume it would be quite similar, but I'm not sure.
PLEASE HELP.
Upvotes: 1
Views: 675
Reputation: 4714
Bitnami Engineer here,
You can use any PostgreSQL client available as NPM package to connect to the PostgreSQL database. For example:
https://www.npmjs.com/package/pg
You can find all the information of this package in its official page
Run this code to start querying the PostgreSQL database
const { Pool, Client } = require('pg')
// pools will use environment variables
// for connection information
const pool = new Pool()
pool.query('SELECT NOW()', (err, res) => {
console.log(err, res)
pool.end()
})
You also need to specify which database to connect to:
PGUSER=dbuser PGHOST=database.server.com PGPASSWORD=secretpassword PGDATABASE=mydb PGPORT=3211 node script.js
Upvotes: 1