fetch(apiURL, setting)
.then(loadRes)
.then(logger)
function loadRes(res){
console.log("loadRes is called");
return res.json();
}
function logger(reply){
stringReply = JSON.stringify(reply);
//console.log("The JSON String " + stringReply)
return new Promise(resolve => {
setTimeout(() => {
resolve(stringReply);
}, 2000);
});
}
async function asyncCall(){
const result = await logger(reply); // a string value i.e "Hello World"
console.log(result); //for testing
}
How do I retrieve the value of stringReply
and place it in the app.post
from a Express
module
app.post('/', function( req, res){
res.send(); //
}
When a value is obtained in function logger(reply)
, I would want it to be able to send it to res.send()
.
I have tried putting res.send(asyncCall())
but it does not work.
Whenever I call asyncCall()
, I would expect a string value.