I want make a function for calling API. If I execute "apifunc", the function calls the api. When the API execution is complete, the results are saved in "body". Now I want the function to return the "body". But it does not. The console did print out the "body". So the api worked. The problem here is return. How do I fix this problem.
exports.apifunc=function(a,b){
var request = require('request');
request.post(`https://abc.co.kr/api/${address}`,
{ json: {A:`${a}`, B: `${b}`} },
function (error, response2, body) {
if (!error && response2.statusCode == 200) {
console.log(body);
return body;
}
});
}