I am new to NodeJS and Promise functionality, so please be polite if this is an uninformed question.
I try to read the records database first and then check if the links really work (search for 200 answer). For my current test data, this should always return a 200 response. I get a 302 response (too many requests), and then the development server crashes. I need to slow down how I send queries to the database, but I cannot figure out how to do this. It seems to me that a promise simply sends everything as soon as it is resolved.
I tried to build time delays in this section, but to no avail. Here is the code:
var http404Promise = new Promise(function(resolve, reject) {
var linkArray = new Array()
db.sequelize.query(photoQuery, {
replacements: queryParams
}).spread(function(photoLinks) {
photoLinks.forEach(function(obj) {
var siteLink = hostname + 'photo/' + obj.img_id
linkArray.push(siteLink)
});
resolve(linkArray);
});
});
http404Promise.then(function(linkArray) {
linkArray.forEach(function(element) {
console.log(element);
http.get(element, function(res) {
console.log(element);
console.log("statusCode: ", res.statusCode);
}).on('error', function(e) {
console.log(element);
console.error(e);
})
})
});
source
share