How to convert Promise to async await in node js

i am trying to convert different code with promise to async await. as i am new to node and dont have much idea about promise can anybody help me with the following example. my vs code doesn’t highlight the promise syntax.

module.exports = {
execSqlQuery: function (procedure, parameters) {
return new Promise(function (fulfill, reject) {
  var request = new sql.Request(connPool);
  parameters.forEach(function (parameter) {
    request.input(parameter.name, parameter.type, parameter.value);
  });
  request.execute(procedure, function (err, recordSets) {
    if (err) {
      reject(err);
    }
    else {
      fulfill(recordSets);
    }
  });
});
},

Answer

First, check whether request.execute has a promise version rather than a callback version. If not you can use promisify library to make it a promise.

const util = require('util');
const execute= util.promisify(sql.execute); 

const execSqlQuery = async (procedure, parameters) => {     
    var request = new sql.Request(connPool);
    parameters.forEach(function (parameter) {
        request.input(parameter.name, parameter.type, parameter.value);
      });
    var recordSets = await  request.execute(procedure)
    return recordSets;
}