In react-native I have this function:
export default async function get_happy_songs(param) {
let emotion = param;
console.log(emotion)
let urlOfS = 'http://10.0.2.2:5000/happy_songs'
return fetch(urlOfS, {
method: 'GET'
}).then((response) => response.json())
.then((responseJson) => {
console.log('response object:', responseJson)
return responseJson;
})
.catch((error) => {
console.error(error);
});
}
and what I want to do is pass variable "emotion" to the NodeJs backend route .../happy_songs and to be able to get this variable in the backend route and to use it there. Here is the route implementation:
app.get('/happy_songs',function(req,res) {
var resultArray = [];
var cursor = db.collection('songs1').find({label: "happy"},{songName:1});
cursor.forEach(function(doc, err) {
resultArray.push(doc);
}, function() {
var songsNames = [];
for (var i = 0; i < resultArray.length; ++i) {
songsNames.push(resultArray[i].songName);
}
var json_response = {melodies:songsNames}
res.json(json_response)
})
Anyone has any idea how can I do that ?
I know it supposed to be very simple, but I am not familiar with this languages, please help me ..