A
A
Andrey Salnikov2016-09-22 20:36:39
JavaScript
Andrey Salnikov, 2016-09-22 20:36:39

How to download pictures synchronously?

There is a site, from it it is necessary to download pictures. I did it in python, no problem. Everything is synchronous and sequential. The server is not overloaded with requests and does not block me.
Now I'm trying to learn Node.js And it all comes down to asynchrony. I have for example a list of 30 images.

for(var i = 0; i < arr.length; i++){
  request(arr[i]).pipe(fs.createWriteStream(name))
}

Through such a piece is useless. Requests are asynchronous, so they become almost parallel in one second and the site starts blocking me.
They write that you need to use Promise. Either from ES6 or libraries like vow. But how? Tell me please. How to work with promises in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Korotaev, 2016-09-22
@Shshzik

You need to look for the npm module for synchronous requests to the server, for a grabber this is just right https://github.com/ForbesLindesay/sync-request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question