I am trying to learn how to use javascript to connect to a postgresql database but when I try to log a query to the console using query.on(...), I get a type error that says \"q
As Mentioned by Denys Séguret in Answer, the function query.on
is deprecated. And if you are a beginner and want to get a quick connection to try out your queries without being bothered by async/await functionality. You can try the below code:-
const { Pool, Client } = require('pg')
const connectionString = 'postgresql://dbuser:dbpassword@database.server.com:5432/mydb'
const pool = new Pool({
connectionString: connectionString,
})
pool.query('SELECT NOW()', (err, res) => {
console.log(err, res)
pool.end()
})