So I'm building a Node.js app and I want to have a file where I do all the required http requests using Axios. Axios' requests return promises, with the http response in the "then" block. I want to export the response to my main file, but when I do that and log the result out, I get
Promise { <pending> }
The file where I do the requests:
const axios = require('axios');
exports.allCountries = () => {
return axios
.get('https://someapi.com')
.then(response => {
return response;
})
.catch(error => {
console.log(error);
});
};
My main file:
const fetch = require('./fetch'); // file with all requests
let countriesResponse = fetch.allCountries();
console.log(countriesResponse); // This logs Promise { <pending> } instead of the actual response