How can I make request results available as a property of the object? At the moment, console.log(album.artistName) returns undefined. However, if I console.log album.name within the request function, the console will return the album name.
I'd like to be able to create my own object that includes the data points I need so I can access universally.
var request = require('request');
var album = {};
album.max = 'Max';
album.artistName = artistName();
function artistName(){
request('https://api.spotify.com/v1/albums/4INyHv55ddXe0A2TNvKezm', function(err, response){
if(!err && response.statusCode == 200){
var data = JSON.parse(response.body);
album.name = data.artists[0].name;
}
});
}
console.log(album);