I'm trying to send a get request to the server. But I'm getting the following error, any idea how to avoid the error?
the error:
events.js:183 throw er; // Unhandled 'error' event ^
Error: connect ECONNREFUSED ****** at Object._errnoException (util.js:992:11) at _exceptionWithHostPort (util.js:1014:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
my request:
var https = require("https");
// Update these options with the details of the web service you would like to call
var options = {
method: 'GET',
uri: 'https:*****',
resolveWithFullResponse: true,
json: true
};
var req = https.request(options, res => {
res.setEncoding('utf8');
var returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log('returndata: ' + JSON.stringify(returnData))
var pop = JSON.parse(returnData).population;
callback(pop);
});
});
req.end();