Categories
JavaScript Answers

How to use the Node.js PostgreSql module?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *