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();
node.js postgresql api azure xmlhttprequest
New contributor
add a comment |
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();
node.js postgresql api azure xmlhttprequest
New contributor
what do you mean by 'not expected' ? Do you get any error?
– xan_z
Nov 17 at 4:31
add a comment |
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();
node.js postgresql api azure xmlhttprequest
New contributor
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
node.js postgresql api azure xmlhttprequest
New contributor
New contributor
edited Nov 17 at 8:55
Robin Green
21.8k873150
21.8k873150
New contributor
asked Nov 17 at 4:15
Siddharth Sharma
12
12
New contributor
New contributor
what do you mean by 'not expected' ? Do you get any error?
– xan_z
Nov 17 at 4:31
add a comment |
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
add a comment |
active
oldest
votes
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
what do you mean by 'not expected' ? Do you get any error?
– xan_z
Nov 17 at 4:31