My Nodejs Code:
i am trying to download files (excel) from a server and parse those excel files and from that data store only required data into mysql database i may download multiple files for that my loop may get interrupted so how to do my below code to run in a series of synchronous way
var r=0;
if (issue.fields.attachment != '') {
while (typeof issue.fields.attachment[r] != "undefined") {
if (typeof issue.fields.attachment[r].content != "undefined") {
var url = issue.fields.attachment[r].content;
request({
method: "GET",
"url": url,
"headers": { "Content-Type": "application/json", }
}, function(err, data, body) {
console.log('file downloading');
}).pipe(fs.createWriteStream('file.xlsx'));
console.log('file downloaded');
parseXlsx('file.xlsx', function(err, data) {
var i, j, k = 1, l = 0, m = 0, n = 0;
console.log('parseXlsx cmpleted');
while (data[i] != undefined) {
if (data[i][j] != '' || data[i][k] != '' || data[i][l] != '') {
var query = connection.query('insert into IP values ("' + data[i][j] + '","' + data[i][k] + '","' + data[i][l] + '","' + data[i][m] + '")',
function(error, results, fields) {
});
}
i++;
}
});
r++;
console.log('rvalue' + r);
}
}
}