Is there an equivelate method to fs.createReadStream() in Node for remote files? Using as follows throws Unhandled \'error\' event
var s = fs.cr
Node is no PHP :)
Use the request module:
request('http://fromrussiawithlove.com/baby.mp3').pipe(fs.createWriteStream('song.mp3'))
It could be better to use a module like request (alternatives), but you could do it like this:
ES6 version
http.get('some_mp3_url', res => res.pipe(fs.createWriteStream('some.mp3')));
ES5 version
http.get('some_mp3_url', function (res) {
res.pipe(fs.createWriteStream('some.mp3'));
});
Note: besides fs
, the http
(or https
) module also has to be imported/required.