My current issue involves making a get request using the following code snippet:
router.get('/marketUpdates',((request, response) => {
console.log("market updates");
var data: Order[]
axios.get('http://localhost:8082/marketUpdates')
.then(function (response) {
console.log("GET Response")
console.log(response.data);
data = response.data;
})
.catch(function (error) {
console.log("Error in fetching market updates");
});
console.log("Data before sending is ")
console.log(data);
response.send(data);
}))
However, I am facing a problem where my final console.log statement at the bottom executes before the console.log within the .then block.
This leads to 'data' being undefined when it gets sent. Does anyone have any suggestions on how to resolve this timing issue?