fs.createReadStream()等价于Node中的远程文件

是否有一个等效的方法fs.createReadStream()在节点的远程文件? 使用如下引发Unhandled 'error' event

 var s = fs.createReadStream('some_mp3_url'); 

节点是没有PHP的:)

使用请求模块:

 request('http://fromrussiawithlove.com/baby.mp3').pipe(fs.createWriteStream('song.mp3')) 

最好使用像请求这样的模块,但是你可以这样做:

ES6版本

 http.get('some_mp3_url', res => res.pipe(fs.createWriteStream('some.mp3'))); 

ES5版本

 http.get('some_mp3_url', function (res) { res.pipe(fs.createWriteStream('some.mp3')); }); 

注意:除了fshttp (或https )模块也必须被导入/需要。