I am trying to use async/ await in request module but I cannot get it to run. I need the response function to wait for the request to complete ( the request pulls from data in a search-bar in browser) I have tried using x = await res, which looks like its not allowed, I have also tried let x = await getStockX() to no avail. I understand the need for await so I no longer run into undefined, but have struggled to find it used in this particular setup.
function getStockX(getUrl){
return new Promise(async(resolve, reject) => {
request({
url: 'https://stockx.com/api/products/' + getUrl + '?includes=market¤cy=USD',
method: "GET",
headers: stockxGETHeaders
},
async function(err, res, body){
let x = await getStockX(); // does not work
let x = await res; // does not work
let json = JSON.parse(body)
console.log(json)
resolve(sku)
});
})
}