Nested HTTP request skipped











up vote
0
down vote

favorite












I have this node.js code snippet, that I am running as a WebJob on Azure, with a timer as a trigger. However, the nested HTTP request is not working as expected.



I am trying to query an API, and then send a message to all users in the Postgresql database, using another API.



Here is how I am trying to do this:
(But somehow the MSG91 API call is not being executed, as expected.)



var http = require("http");
var pg = require('pg');

var current_date = new Date();
current_date = current_date.toISOString().slice(0, 10);
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday = yesterday.toISOString().slice(0, 10);
var options = {
"method": "GET",
"hostname": "www.gdacs.org",
"port": 80,
"path": "/export.aspx?profile=ARCHIVE&type=geojson&eventtype=&from=" + yesterday + "&to=" + current_date + "&alertlevel=Orange&severity=&country=",
"headers": {}
};

var req = http.request(options, function (res) {
var chunks = '';

res.on("data", function (chunk) {
chunks += chunk;
});

res.on("end", function () {
var data = JSON.parse(chunks);
event1 = data.features[0].properties.name;
event1 = encodeURIComponent(event1);
if (event1) {

// connect to postgresql server
const config = {
host: '<database-server-name>.postgres.database.azure.com',
user: '******',
password: '******',
database: 'database name',
port: 5432,
ssl: true,
};

const client = new pg.Client(config);
client.connect(err => {
if (err) throw err;
else {

console.log(Running query to PostgreSQL server: ${config.host});

const query = 'SELECT * FROM guests;';

client.query(query)
.then(res => {
const rows = res.rows;

for (var i = 0; i< rows.length; i++) {

var phone = rows[i].phone.toString();

http.get("http://api.msg91.com/api/sendhttp.php?country=91&sender=MSGIND&route=4&mobiles="+phone+"&authkey=1********da25e&message="+ event1, function(res) {
console.log("Got response: " + res.statusCode);
});

console.log(phone);
}


process.exit();
})
.catch(err => {
console.log(err);
});
}
});
}
});
});

req.end();









share|improve this question









New contributor




Siddharth Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • what do you mean by 'not expected' ? Do you get any error?
    – xan_z
    Nov 17 at 4:31















up vote
0
down vote

favorite












I have this node.js code snippet, that I am running as a WebJob on Azure, with a timer as a trigger. However, the nested HTTP request is not working as expected.



I am trying to query an API, and then send a message to all users in the Postgresql database, using another API.



Here is how I am trying to do this:
(But somehow the MSG91 API call is not being executed, as expected.)



var http = require("http");
var pg = require('pg');

var current_date = new Date();
current_date = current_date.toISOString().slice(0, 10);
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday = yesterday.toISOString().slice(0, 10);
var options = {
"method": "GET",
"hostname": "www.gdacs.org",
"port": 80,
"path": "/export.aspx?profile=ARCHIVE&type=geojson&eventtype=&from=" + yesterday + "&to=" + current_date + "&alertlevel=Orange&severity=&country=",
"headers": {}
};

var req = http.request(options, function (res) {
var chunks = '';

res.on("data", function (chunk) {
chunks += chunk;
});

res.on("end", function () {
var data = JSON.parse(chunks);
event1 = data.features[0].properties.name;
event1 = encodeURIComponent(event1);
if (event1) {

// connect to postgresql server
const config = {
host: '<database-server-name>.postgres.database.azure.com',
user: '******',
password: '******',
database: 'database name',
port: 5432,
ssl: true,
};

const client = new pg.Client(config);
client.connect(err => {
if (err) throw err;
else {

console.log(Running query to PostgreSQL server: ${config.host});

const query = 'SELECT * FROM guests;';

client.query(query)
.then(res => {
const rows = res.rows;

for (var i = 0; i< rows.length; i++) {

var phone = rows[i].phone.toString();

http.get("http://api.msg91.com/api/sendhttp.php?country=91&sender=MSGIND&route=4&mobiles="+phone+"&authkey=1********da25e&message="+ event1, function(res) {
console.log("Got response: " + res.statusCode);
});

console.log(phone);
}


process.exit();
})
.catch(err => {
console.log(err);
});
}
});
}
});
});

req.end();









share|improve this question









New contributor




Siddharth Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • what do you mean by 'not expected' ? Do you get any error?
    – xan_z
    Nov 17 at 4:31













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have this node.js code snippet, that I am running as a WebJob on Azure, with a timer as a trigger. However, the nested HTTP request is not working as expected.



I am trying to query an API, and then send a message to all users in the Postgresql database, using another API.



Here is how I am trying to do this:
(But somehow the MSG91 API call is not being executed, as expected.)



var http = require("http");
var pg = require('pg');

var current_date = new Date();
current_date = current_date.toISOString().slice(0, 10);
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday = yesterday.toISOString().slice(0, 10);
var options = {
"method": "GET",
"hostname": "www.gdacs.org",
"port": 80,
"path": "/export.aspx?profile=ARCHIVE&type=geojson&eventtype=&from=" + yesterday + "&to=" + current_date + "&alertlevel=Orange&severity=&country=",
"headers": {}
};

var req = http.request(options, function (res) {
var chunks = '';

res.on("data", function (chunk) {
chunks += chunk;
});

res.on("end", function () {
var data = JSON.parse(chunks);
event1 = data.features[0].properties.name;
event1 = encodeURIComponent(event1);
if (event1) {

// connect to postgresql server
const config = {
host: '<database-server-name>.postgres.database.azure.com',
user: '******',
password: '******',
database: 'database name',
port: 5432,
ssl: true,
};

const client = new pg.Client(config);
client.connect(err => {
if (err) throw err;
else {

console.log(Running query to PostgreSQL server: ${config.host});

const query = 'SELECT * FROM guests;';

client.query(query)
.then(res => {
const rows = res.rows;

for (var i = 0; i< rows.length; i++) {

var phone = rows[i].phone.toString();

http.get("http://api.msg91.com/api/sendhttp.php?country=91&sender=MSGIND&route=4&mobiles="+phone+"&authkey=1********da25e&message="+ event1, function(res) {
console.log("Got response: " + res.statusCode);
});

console.log(phone);
}


process.exit();
})
.catch(err => {
console.log(err);
});
}
});
}
});
});

req.end();









share|improve this question









New contributor




Siddharth Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have this node.js code snippet, that I am running as a WebJob on Azure, with a timer as a trigger. However, the nested HTTP request is not working as expected.



I am trying to query an API, and then send a message to all users in the Postgresql database, using another API.



Here is how I am trying to do this:
(But somehow the MSG91 API call is not being executed, as expected.)



var http = require("http");
var pg = require('pg');

var current_date = new Date();
current_date = current_date.toISOString().slice(0, 10);
var yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
yesterday = yesterday.toISOString().slice(0, 10);
var options = {
"method": "GET",
"hostname": "www.gdacs.org",
"port": 80,
"path": "/export.aspx?profile=ARCHIVE&type=geojson&eventtype=&from=" + yesterday + "&to=" + current_date + "&alertlevel=Orange&severity=&country=",
"headers": {}
};

var req = http.request(options, function (res) {
var chunks = '';

res.on("data", function (chunk) {
chunks += chunk;
});

res.on("end", function () {
var data = JSON.parse(chunks);
event1 = data.features[0].properties.name;
event1 = encodeURIComponent(event1);
if (event1) {

// connect to postgresql server
const config = {
host: '<database-server-name>.postgres.database.azure.com',
user: '******',
password: '******',
database: 'database name',
port: 5432,
ssl: true,
};

const client = new pg.Client(config);
client.connect(err => {
if (err) throw err;
else {

console.log(Running query to PostgreSQL server: ${config.host});

const query = 'SELECT * FROM guests;';

client.query(query)
.then(res => {
const rows = res.rows;

for (var i = 0; i< rows.length; i++) {

var phone = rows[i].phone.toString();

http.get("http://api.msg91.com/api/sendhttp.php?country=91&sender=MSGIND&route=4&mobiles="+phone+"&authkey=1********da25e&message="+ event1, function(res) {
console.log("Got response: " + res.statusCode);
});

console.log(phone);
}


process.exit();
})
.catch(err => {
console.log(err);
});
}
});
}
});
});

req.end();






node.js postgresql api azure xmlhttprequest






share|improve this question









New contributor




Siddharth Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Siddharth Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 17 at 8:55









Robin Green

21.8k873150




21.8k873150






New contributor




Siddharth Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 17 at 4:15









Siddharth Sharma

12




12




New contributor




Siddharth Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Siddharth Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Siddharth Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • what do you mean by 'not expected' ? Do you get any error?
    – xan_z
    Nov 17 at 4:31


















  • what do you mean by 'not expected' ? Do you get any error?
    – xan_z
    Nov 17 at 4:31
















what do you mean by 'not expected' ? Do you get any error?
– xan_z
Nov 17 at 4:31




what do you mean by 'not expected' ? Do you get any error?
– xan_z
Nov 17 at 4:31

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Siddharth Sharma is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348151%2fnested-http-request-skipped%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Siddharth Sharma is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Siddharth Sharma is a new contributor. Be nice, and check out our Code of Conduct.













Siddharth Sharma is a new contributor. Be nice, and check out our Code of Conduct.












Siddharth Sharma is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348151%2fnested-http-request-skipped%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy