Skip to content

Instantly share code, notes, and snippets.

@imbhargav5
Created October 27, 2017 10:00
Show Gist options
  • Save imbhargav5/3506881f38e531ea5d8e400b2efb7803 to your computer and use it in GitHub Desktop.
Save imbhargav5/3506881f38e531ea5d8e400b2efb7803 to your computer and use it in GitHub Desktop.
Download sprites from pokeapi to avoid hot linking
const download = require("image-downloader");
const path = require("path");
const pathExists = require("path-exists");
Array.from({ length: 802 }).forEach((i, index) => {
const entry = index + 1;
const downloadPath = path.join(__dirname, `public/images/${entry}.png`);
pathExists(downloadPath).then(exists => {
if (exists) {
return;
} else {
const options = {
url: `https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/${entry}.png`,
dest: downloadPath
};
download
.image(options)
.then(({ filename, image }) => {
console.log("File saved to", filename);
})
.catch(err => {
throw err;
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment