nodejs version v10.14.2 OS win7 sp1 64bit
I need the following four lines of code to execute in order
var res2 = await fetchData(url_2, file_path_2);
await console.log('step one.');
var res1 = await fetchData(url_1, file_path_1);
await console.log('step two.');
However, the actual order of their execution is
step one. step two. ........ ........
How can we achieve synchronous execution of these four lines of codes?
var https = require('https');
var fs = require('fs');
var request = require('request');
var async = require("async");
(async() => {
var url_1 = 'https://aaa.bbb.ccc.com';
var url_2 = 'https://library.harvard.edu/';
var file_path_1 = fs.createWriteStream('./intelcenter/aaa.bbb.ccc.txt');
var file_path_2 = fs.createWriteStream('./intelcenter/harvard.txt');
var res2 = await fetchData(url_2, file_path_2);
await console.log('step one.');
var res1 = await fetchData(url_1, file_path_1);
await console.log('step two.');
})();
async function fetchData(url,locpath) {
return new Promise(function (resolve) {
async.retry(request(url).pipe(locpath), function(err, result) {
resolve(result);
});
});
}