I am trying to access the Microsoft Azure Management API, and I have gotten to the point where I can console.log() the data from my axios call.
What I can't figure out how to do, is how do I wrap my axios call in a function, and then retrieve that data later on?
My code is below. Note that I see the returned data from the MS api in my console, just like I'd expect.
// Express setup code, module imports, env variables, etc.
// ...
function getAzureToken() {
// Set up credentials, auth url and request body, axios config
// The API authenticates properly, so it is not relevant to include
// ...
var data = {};
axios.post(authEndpoint, config)
.then(result => {
console.log(result.data) // Logs the expected data (auth token) in my console
data = result.data
})
return data
}
// Index API endpoint
app.get('/', (req, res) => {
let token = getAzureToken()
// Prints out this in my browser: {}
res.send(token)
})
Can anyone give a noob a helping hand?