I want to make a loop that downloads a file on an interval. But I can't make the setTimeout function work when the request function needs a parameter. It's the last line of the progam that i failing. What am I doing wrong?
const http = require('http');
const fs = require('fs');
const file = fs.createWriteStream("file.jpg");
const fileToDownload = "http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg";
function request1() {
http.get(fileToDownload, function(response) {
response.pipe(file)
});
}
function request2(saveName) {
const save = fs.createWriteStream(saveName);
http.get(fileToDownload, function(response) {
response.pipe(save)
});
}
setTimeout(request1, 3000);
setTimeout(request2("file2.jpg"), 3000); // TypeError: "callback" argument must be a function