I would have a simple question but can't figure it out the answer with Node.JS. Here it is : I got a file with multiple function and I would like to use the return of the first inside the second :
//The first function
const Function1 = (req, res) => {
var axios = require('axios');
var config = {
method: 'get',
url: 'xxxxx.json',
headers: {
//...
}
};
axios(config).then(function(response) {
const array = response.data.datas
return Promise.all(Object.values(array).map(entry => {
return entry.id
}))
}).then(function(response) {
//I got an array with infos
return response
}).catch(function(error) {
console.log(error);
});
}
const Function2 = (req, res) => {
const previousResult = function1()
//Undefined
console.log(previousResult)
}
How should I proceed ?
Thanks a lot