I made a function because I wanted to return the data received by request(get) in a variable If you take a function,
Promise { <pending>}
It pops up like this. I don't know what to do, so I'm asking you a question!
Code
const getData=async(gn)=> {
let gameData = undefined;
gameData = await rq({
method: "GET",
url: base_url + "/get_gameData/OXquiz",
}).then(function (response) {
return response;
});
return gameData;
};
console.log(getData("OXquiz"));
If you take a response in then, the value comes out well <
node.js
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
function get_data (url){
return new Promise((resolve, reject)=>{
rq({
method: "GET",
url: url
})
.then((res)=>{
resolve(res);
})
.catch((err)=>{
reject(err)
});
});
}
getData("http://somewhere/get_gameData/OXquiz")
.then((res)=>{
console.log(res);
})
.catch((err)=>{
console.error(err);
});
© 2024 OneMinuteCode. All rights reserved.