Friday, 5 May 2017

how to download audio file from url in node js?

how to download audio file from an url and store it in local directory? using node js i tried the following code.. no error occured but cant able to find the file

'var http = require('http');
 var fs = require('fs');
 var dest = 'C./test'
 var url= 'http://static1.grsites.com/archive/sounds/comic/comic002.wav'
 function download(url, dest, callback) {
    var file = fs.createWriteStream(dest);
    var request = http.get(url, function (response) {
        response.pipe(file);
        file.on('finish', function () {
            file.close(callback); // close() is async, call callback after close completes.
         });
        file.on('error', function (err) {
             fs.unlink(dest); // Delete the file async. (But we don't check the result)
            if (callback)
                 callback(err.message);
        });
     });
  }'



via RajaSekar

No comments:

Post a Comment