I have the following code in node (beginner), I want to call a function after all the code has been executed in the loop, I know that I have to use promises, but I don't know how to apply them in this situation. The code has been simplified. Many thanks.
const axios = require('axios').default;
axios.post('url', {
params: {}
}).then(response=>{
var objResponse = response.data
Object.keys(objResponse).forEach(function (key){
axios.post('url', {
params: {}
}).then(response=>{
var n=0;
getCode(n);
})
})
**finishFunction**()
})
function getCode(n) {
axios.post('url', {
params: {}
}).then(response=>{
if(response.data){
if (response.data.code) {
getData();
}else{
if (n < 10) {
n++;
getCode(n);
} else {
getTimeout();
}
}
}
})
}
function getTimeout() {
axios.post('url', {
params: {}
})
}
function getData() {
axios.post('url', {
params: {}
}).then(response=>{
console.log('finished one loop');
})
}