Skip to content
Discussion options

You must be logged in to vote

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);

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@raphaelcockx
Comment options

@sindresorhus
Comment options

Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #596 on June 24, 2024 18:14.