What is the proper way to use the node.js postgresql module?

后端 未结 7 1827
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 01:15

I am writing a node.js app on Heroku and using the pg module. I can\'t figure out the \"right\" way to get a client object for each request that I need to query the database

7条回答
  •  迷失自我
    2020-11-28 01:27

    Pool is the way to go now.Some thing like this

    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)
          }
    

    it can be used as db.query('

提交回复
热议问题