I have a google cloud function using this code and it gives the error TypeError: pg.Pool is not a constructor at exports.postgresDemo I have
{
"dependencies": {
"pg": "^2.0.5"
}
}
as the dependencies. I don't know if the error is in node or cloud functions
Should have been obvious from your dependencies :
"dependencies": {
"pg": "^2.0.5"
}
}
I ran this:
const pg = require('pg')
const pool = new pg.Pool()
console.log(pool)
and got the expected result. Difference is, in my dependencies, I have :"pg": "^7.7.1"
. The google example you are using also uses a more recent version of pg.
I tried to install your version to double check using npm install pg@2.0.5
but got the error: npm ERR! notarget No matching version found for pg@2.0.5
So upgrade pg and it will work