Javascript/Nodejs Downloading audio file to disk

319 Views Asked by At

Looking to download this wav file. Response.pipe(fileStrm) isn't doing it for me. Ive looked around. Wondering what the standard way of downloading media from a URL to file is these days.

const request = require('request').defaults({rejectUnauthorized:false});
const url = "https://..../00015.wav";
const path ="./data/my.wav";

async function getVideo22(url,path){
    var options = { 
    'method': 'GET',
     'url': url,
     'headers': {
     }
   };
   var fileStrm = fs.createWriteStream(path);

   request(options, function (error, response) {
        if (error) throw new Error(error);
       //need to write file to disk
        
       response.pipe(fileStrm);
});

}
1

There are 1 best solutions below

0
On

Knew it was simple

 const path = "....";
 try {
       const url = "....";
       request(url)
       .pipe(fs.createWriteStream(path));

    } catch...