I want to download a file remotely but when I try to write it in the disk it's empty.
I tried this solution https://stackoverflow.com/a/12751657 with no success.
in my app (downloader)
function download(url, filename, callback){
request.head(url, function(err, res, body){
if(err){
alert("An error occured while downloading data remotely.");
}else{
request(url).pipe(fs.createWriteStream(filename)).on('close', callback);
}
});
}
download('http://localhost:3000/db/user', user.db, function(){
alert("Success");
});
In my remote server
app.get('/db/user', function(req, res){
res.sendFile('data/user.txt', {root: __dirname});
});
but when i check user.db it's empty.