Is there an equivelate method to fs.createReadStream() in Node for remote files? Using as follows throws Unhandled 'error' event
var s = fs.createReadStream('some_mp3_url');
The function fs. createReadStream() allows you to open up a readable stream in a very simple manner. All you have to do is pass the path of the file to start streaming in. It turns out that the response (as well as the request) objects are streams.
createReadStream() and follow what it calls you can find that it ends up calling fileURULtoPath(url) which will throw if it's not a file: URL. It would suggest using the got() library to get yourself a readstream from a URL: const got = require('got'); const mp4Url = 'https://www.example.com/path/to/mp4Video.mp4'; app.
createReadStream() appears to have a synchronous interface. It does not return a promise or accept a callback to communicate back when it's done or to send back some results. So, it appears synchronous from the interface.
Node is no PHP :)
Use the request module:
request('http://fromrussiawithlove.com/baby.mp3').pipe(fs.createWriteStream('song.mp3'))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With