I'm fairly new to node fetch and I'm doing a simple get request to get a list of my postman collections. I'm able to get the response text and console log it in the function but when I'm returning the responseText to a variable and logging it, I get an empty result,could someone suggest why?
const fetch = require("node-fetch");
async function getCollections() {
var myHeaders = new fetch.Headers();
myHeaders.append(
"X-Api-Key",
"<API-KEY>"
);
var requestOptions = {
method: "GET",
headers: myHeaders,
};
url = "https://api.getpostman.com/collections";
const requestResponse = await fetch(url, requestOptions);
const response = await requestResponse.text();
return response;
}
const result = getCollections();
console.log(result);