pool.request() 不是函数

pool.request() is not a function

enter code here

**my dbconnection.js**  

  const sql = require("mssql");
const config = {
    user: 'sa',
    password: 'abhi',
    server: 'ABHI\MSSQLSERVER01', 
    database: 'online_video_streaming' 
};
const poolPromise =new sql.ConnectionPool(config)
    .connect()
     .then (pool =>{
        console.log("connected")
            return pool.request()
        }).catch(err => console.log("failed to connect", err));
console.log("connection", poolPromise)
  module.exports = {
                    poolPromise:poolPromise,
                    sql:sql
                };

**my users.js**
const {sql,poolPromise} = require('../../dbconnection');
router.post('/getcatlist', async (req, res) => {
  try{
    const pool = await poolPromise;
    const request = await pool.request();
  let userquery = 'SELECT  * FROM cat_1_level_1';
  let response = await request.query(userquery);
  res.send("200",response);
  console.log(response);
}catch (e){
  console.error(e)
}
});

输出: tedious deprecated 在 tedious 的下一个主要版本中,config.options.enableArithAbort 的默认值将从 false 更改为 true。明确地将值设置为 truefalse 以使此消息静音。 node_modules\mssql\lib\tedious\connection-pool.js:61:23

连接承诺{待定} 连接的 类型错误:pool.request 不是一个函数 在 C:\Users\ABHILASH M\Desktop\nodejs\Online_video_streaming2\routes\portal\manage\user.js:430:32 在 processTicksAndRejections (internal/process/task_queues.js:97:5)

您将在 db.js 返回 pool.request()

改为这样做:

const poolPromise =new sql.ConnectionPool(config)
    .connect()
    .then (pool =>{
        console.log("connected")
        return pool
    })
    .catch(err => console.log("failed to connect", err)); 

此外,您从 const 开始做得很好,但随后您开始将事物声明为永远不会发生变化的可变事物。将那些 let 语句更改为 const,您将继续#winning。参见 this article