Q:

NODE JS | MS API facing issues while multiple connection connected to API

I just wanted to be so clear as I can, So I have an MS SQL nodejs API, through which I interact with my android and Desktop Application. Currently its working fine, but it is not on pool connection. I think that is why when more people use my app it just doesn't give the response and gives an error more LIKE 
Connection already exists close SQL.close() first
So I was planning on upgrading my API to pool connection, by which means more people can connect to my API simultaneously. Right? 
So I have this connection to the DB code that has the connection and query look like this :
Connection var dbConfig = {
    user: 'sa',
    password: "pmis13",
    server: '19',
    database: 'CUBES_HO',
};

Query handler :
function executeQuery(query) {
return new Promise((resolve, reject) => {
    sql.connect(dbConfig, function (err) {
        if (err) {
            reject(err);
            sql.close();
        } else {
            // create Request object
            var request = new sql.Request();
            // query to the database and get the records
            request.query(query, function (err, data) {
                if (err) {
                    reject(err);
                    sql.close();
                } else {
                    resolve(data);
                    sql.close();
                }
            });
        }
    });
});}

And the query look like this :
app.get("/dailysale/:date", function (req, res) {
var query = "SELECT SUM(bill_amt) AS totalSale FROM [CUBES_HO].[dbo].[vw_bill_summary] where inv_loc_key = 2 and  bill_sale_date =  '"+req.params.date+"'";
executeQuery(query)
    .then((data) => {
        res.status(200).send({ "msg": "Records fetched", "data": data.recordsets });
    }).catch((err) => {
        res.status(500).json({ "msg": err.message });
    });});

I want to convert this or we can say upgrade this api to pool connection, which sounds more reliable for multiple connection. Correct me I am wrong.  

A:

I found a work arround by doing this 
    var config     ={
    user: 'sa',
    password: "pdt09",
    server: '3',
    database: 'CUBES',
    options: {encrypt: true}  
  };

 async function executeQuery(sqlquery) {
return new Promise(function(resolve, reject) {
(async() => {
  const pool = new sql.ConnectionPool(config);
  pool.on('error', err => {
    // ... error handler 
    console.log('sql errors', err);
  });

  try {

    await pool.connect();
    let data = await pool.request().query(sqlquery);

  resolve(data);

  } catch (err) { 
    reject(err)
  } finally {
    pool.close(); //closing connection after request is finished.
  }
})(); 
}).catch(function(err) {

});

}

and the worker will remain the same

