I want to call the function getData from inside the single_view function. in the below code the output of getData is return as undefined
var request = require("request");
module.exports = {
    getData: (url) => {
        request(url, function (error, response, body) {
            if (!error && response.statusCode == 200) {
                return {success: false, data: JSON.parse(body)};
            }
            else{
                return {success: false, data: "API call failed"};
            }
        });
    },
    singleView: (req, res) => {
        var post_url = "http://example.in/wp-json/wp/v2/posts?slug="+req.params.postSlug;
        var post_api_data = module.exports.getData(post_url);
        if(post_api_data['success'] == true && post_api_data['data'].length > 0){
    }
}
In the singleView controller, the route returns undefined. How do I fix this?
 
    