Skip to content

How to fetch() a file to specific directory? #17026

Answered by ayame113
Kenya-West asked this question in Q&A
Discussion options

You must be logged in to vote

To write the fetch result to a file, the following should work.

const { body } = await fetch("https://google.com");
const file = await Deno.open("./tmp/tmp.txt", { append: true, create: true });
body?.pipeTo(file.writable);

The following should also work.

const res = await fetch("https://google.com");
const content = await res.text();
await Deno.writeTextFile("./path/to/dir", content);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Kenya-West
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants