1

I'm trying to figure out how to use a download link to download a file in node.js. When I enter in the following link (Download Subtitles for the Godfather) into my web browser it will automatically download the file that contains the subtitles. How do I do this in node? And is there a way to name the file as I want it to be named as well as choose it's path? Thank you in advance!

pbie42
  • 605
  • 1
  • 6
  • 12

1 Answers1

0
var http = require('http');
var fs = require('fs');

var file = fs.createWriteStream("file.jpg");
var request = http.get("http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg", function(response) {
  response.pipe(file);
});

https://stackoverflow.com/a/11944984/4258088

Community
  • 1
  • 1
MoeSattler
  • 6,684
  • 6
  • 24
  • 44