I need to get the responses from three http requests serially in their order.
I was able to do this with nested functions. I also need to use the response from the last request in the global scope, which i am not able to do with the nesting solution.
var request = require("request");
httpRequest1((getRequest1) => {
console.log(getRequest1);
httpRequest2((getRequest2) => {
console.log(getRequest2);
httpRequest3((getRequest3) => {
console.log(getRequest3);
});
});
});
function httpRequest1 (callback){
var options = { method: 'POST',
url: };
request(options, function (error, response, body) {
if (error) throw new Error(error);
callback (body);
});}
function httpRequest2(callback){
var options = { method: 'POST',
url: };
request(options, function (error, response, body) {
if (error) throw new Error(error);
callback(body);
});}
function httpRequest3(callback){
var options = { method: 'POST',
url: };
request(options, function (error, response, body) {
if (error) throw new Error(error);
callback(body);
});}