Skip to content

Instantly share code, notes, and snippets.

@ahmed-com
Created February 11, 2022 11:18
Show Gist options
  • Save ahmed-com/cb3c671f0697528db2e328cf7f6b1ecd to your computer and use it in GitHub Desktop.
Save ahmed-com/cb3c671f0697528db2e328cf7f6b1ecd to your computer and use it in GitHub Desktop.
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