Gloomy Gloomy - 4 months ago 16
Node.js Question

How do I save a downloaded file to the file system? (node.js)

I am trying to make a small scraper with node (electron) for learning purposes. I am stuck at trying to download files from the webpage.

For now I do :

return response.arrayBuffer();
var buff = new Int32Array(buffer);

But the fs part is wrong - I just can't figure out how to make it right. How do I know what sort of data (uint8, int32, etc.) I should use? I'm really confused about how this should work.


Assuming you're running Electron v0.37.5 or later, I think this should do the trick:

fetch(fileUrl).then(response => {
  var buff = Buffer.from(response.arrayBuffer());
  fsp.writeFile("filename.pdf", buff).then(() => {