Skip to content

Instantly share code, notes, and snippets.

@adnanirfan
Created March 6, 2023 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adnanirfan/d465f41f936be161bd0c7d5eb53b2393 to your computer and use it in GitHub Desktop.
Save adnanirfan/d465f41f936be161bd0c7d5eb53b2393 to your computer and use it in GitHub Desktop.
import axios from 'axios';
import fs from 'fs';
const images = ["https://avatars.githubusercontent.com/u/9200214?s=500&v=2"];
(async () => {
function getImage(url, index) {
try {
axios({
method: 'get',
url,
responseType: 'stream',
})
.then((response) => {
// Pipe the image stream to a file
response.data.pipe(fs.createWriteStream(`image-${index}.jpg`));
})
.catch((error) => {
console.log(error);
});
} catch (error) {
console.log('===== ERROR:', error);
}
}
for (let index in images) {
console.log(index);
getImage(images[index], index);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment