Skip to content

Instantly share code, notes, and snippets.

@iwstkhr
Last active May 22, 2024 16:30
Show Gist options
  • Save iwstkhr/fdd6e00576e52d55e8f74e24abcf940a to your computer and use it in GitHub Desktop.
Save iwstkhr/fdd6e00576e52d55e8f74e24abcf940a to your computer and use it in GitHub Desktop.
Downloading Data by Node.js
import fs from 'fs';
export async function download(url: string, file: string): Promise<void> {
// See https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
const response = await fetch(url);
if (!response.ok) {
return;
}
const data = Buffer.from(await response.arrayBuffer());
fs.writeFileSync(file, data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment