- I am getting some data from spotify api.
- Creating an object and saving some values from the returned JSON data
return the object 4.. trying to display the object data.
/* API ROUTES */ router.get('/', (req, res) => { // Get artist const data = getArtist('Drake'); if(data) { console.log(data.id); } else { console.log('nothing in data'); } }); // Get an artist name function getArtist(name) { spotify .search({ type: 'artist', query: name }) .then(function(response) { // Gets Name and Id of the artist const data = { "id": response.artists.items[1].id, "name": response.artists.items[1].name } return data; }) .catch(function(err) { console.log(err); }); }
Displays the error: nothing in data.
Coming from JAVA not sure what I am doing wrong in Javascript. Ideas? Is there a better way?