Created
May 28, 2023 11:30
-
-
Save cecilemuller/83fdea6b50accdbe1e1e7e4dc98d84d2 to your computer and use it in GitHub Desktop.
Download to file (Node 18)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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