Q:

Node.JS function the returns http response value

I need to call a function that makes an http request and have it return the value to me through callback. However, when I try I keep getting null response. Any help?
Here is my code:
var url = 'www.someurl.com'
makeCall(url, function(results){return results})

makeCall = function (url, results) {
          https.get(url,function (res) {
           res.on('data', function (d) {
                    resObj = JSON.parse(d);
                    results(resObj.value)

                });
            }).on('error', function (e) {
                     console.error(e);
                });
        }

A:

You need to restructure your code to use a callback instead of returning a value. Here is a modified example that gets your external IP address:
var http = require('http');

var url = 'http://ip-api.com/json';

function makeCall (url, callback) {
    http.get(url,function (res) {
        res.on('data', function (d) {
            callback(JSON.parse(d));
        });
        res.on('error', function (e) {
            console.error(e);
        });
    });
}

function handleResults(results){
    //do something with the results
}

makeCall(url, function(results){
    console.log('results:',results);
    handleResults(results);        
});

