I have array of remote files address. I simply use for in to foreach array and in body of foreach, I starting HTTP GET request for data download. But everything is async and I need to know filename to save the file in request callback.
What is the best practice to solve this?
Demo code:
files = ["url.com/file.png", "url.com/file.doc"]
for file in files
req = http.get file, (response) =>
response.setEncoding 'binary'
body = ""
response.on "data", (chunk) =>
body += chunk
response.on "end", () =>
#Here I needs to know the file name to save it
fs.writeFileSync @currentFolder + "/Files/" + file, body, "binary"
Thank you!
url.com/file.pngtofile.png?