To use the Node.js PostgreSql module, we create a connection pool.
For instance, we write
const { Pool } = require("pg");
const pool = new Pool({
connectionString: DATABASE_URL,
ssl: false,
max: 20,
idleTimeoutMillis: 30000,
connectionTimeoutMillis: 2000,
});
module.exports = {
query: (text, params) => pool.query(text, params),
};
to create a new Pool object to to create the connection pool.
Then we call pool.query to make a query to the database with the text SQL command and params parameters.