I'm downloading a file in the code bellow...
var download = function(uri, filename, callback, path) {
request
.get(uri)
.on('response', function (response) {
var responseType = (response.headers['content-type'] || '').split(';')[0].trim();
var ext = mime.extension(responseType);
filename += '.' + ext;
var fileStream = fs.createWriteStream(filename)
.on('finish', function () {
});
this.pipe(fileStream);
path = filename; //this doesn't work, the path by reference gets empty
});
//I've tried setting a variable here with the file name's value and
//returning it here but it's returning empty value
};
Everything works fine but i need a way to return the filename to the function caller, but it comes empty, i can't set even a variable by reference with this filename value inside the request function.. Could somebody help me? thanks in advance