Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Created May 28, 2023 11:30
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 cecilemuller/83fdea6b50accdbe1e1e7e4dc98d84d2 to your computer and use it in GitHub Desktop.
Save cecilemuller/83fdea6b50accdbe1e1e7e4dc98d84d2 to your computer and use it in GitHub Desktop.
Download to file (Node 18)
import {createWriteStream} from "fs";
import {pipeline} from "stream/promises";
try {
const response = await fetch("https://github.githubassets.com/images/modules/logos_page/Octocat.png");
if (!response.ok) {
throw new Error(response.statusText);
} else {
await pipeline(response.body, createWriteStream("Octocat.png"));
}
} catch (e) {
console.log(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment