I need to be able to retrieve a PDF document from a URL and pass it to another function which will eventually store it in a database. I have found many solutions for DOWNLOADING files to local storage but I do not want to do this. The simplest method to grab the file that I found looks like this:
var http = require('http');
var fs = require('fs');
var download = function(url, dest, cb) {
var file = fs.createWriteStream(dest);
var request = http.get(url, function(response) {
response.pipe(file);
file.on('finish', function() {
file.close(cb);
});
});
}
How do I take the information from the request and stick it into a constant so i can then use it in another function?
Thanks