Created
February 11, 2022 11:18
-
-
Save ahmed-com/cb3c671f0697528db2e328cf7f6b1ecd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const https = require('https'); | |
const fs = require('fs'); | |
let counter = 13; | |
const options = { | |
hostname: 'thispersondoesnotexist.com', | |
port: 443, | |
path: '/image', | |
method: 'GET', | |
}; | |
function waitSynchronously(time) { | |
const start = Date.now(); | |
while(Date.now() < start + time){} | |
return; | |
} | |
function downloadImage() { | |
if(counter > 100) return; | |
waitSynchronously(2000) | |
counter++; | |
const req = https.request(options, (res) => { | |
const writeToFile = fs.createWriteStream(`./people/${counter}.jpg`); | |
res.pipe(writeToFile); | |
req.on('error', (error) => { | |
console.error(error); | |
}); | |
}); | |
req.end(downloadImage); | |
} | |
downloadImage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment