How to download files from external host #597
-
|
I have a list of filenames i need to download from a website. In nodejs how would i download these files in parallel using |
Beta Was this translation helpful? Give feedback.
Answered by
sindresorhus
Jun 24, 2024
Replies: 1 comment 2 replies
-
|
Something like this (untested): import ky from 'ky';
import {writeFile} from 'fs/promises';
async function downloadFiles(fileNames, downloadUrl) {
await Promise.all(
fileNames.map(async fileName => {
const file = await ky.get(`${downloadUrl}/${fileName}`).bytes();
await writeFile(fileName, file);
})
);
}
const fileNames = ['file1.txt', 'file2.txt']; // Replace with your filenames
const downloadUrl = 'https://example.com/files'; // Replace with your download URL
await downloadFiles(fileNames, downloadUrl); |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
sindresorhus
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something like this (untested):