Answer the question
In order to leave comments, you need to log in
How to disable asynchrony in node.js http.get()?
The point is the following. There is a file with a lot of links to different files. These files need to be downloaded.
I try to do it like this:
var http = require('http');
var fs = require('fs');
function readFile(nameFile) {
fs.readFile(nameFile, 'utf8', function(err, contents) {
if (!err) {
readLine(contents.split('\n'));
} else {
console.log('Ошибка', err);
}
});
}
function readLine(array) {
array.forEach(function(uri) {
var img_name = decodeURIComponent(uri.split('/').slice(-1))
var file = fs.createWriteStream(img_name);
var request = http.get(uri, function (response) {
console.log(img_name, ' OK')
response.pipe(file);
});
});
}
readFile('test.txt');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question