0

I have below code in python

urllib.urlretrieve(URL, basePath +ldnumber +".pdf")

I think what above code do is download data from given url and save it as second parameter "basePath + str(ldnumber)+".pdf".

I have written below code in node js to achieve same functionality:

var file = fs.createWriteStream(basePath +ldnumber +".pdf");
   var request = http.get(URL, function(response)
   {
      response.pipe(file);
   });

But above code is just create a file for given basepath and not what I require to achieve.

Is there any way to download a file and save it on given destination path in node js.

I am sure there must be some proper way but I am running little out of time so I am posting this question here till I find an answer to this.

Always_a_learner
  • 4,585
  • 13
  • 63
  • 112
  • What do you want to achieve exactly? – Sandesh K Feb 16 '17 at 12:32
  • I have a url of image or PDF and I want to download it to given path. I referred this question 'http://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries' but got an error "Cannot read property 'get' of undefined". Can we use 'request' package of node to achieve this? – Always_a_learner Feb 16 '17 at 12:39

0 Answers0