You can create an HTTP GET request and pipe its response into a writable file stream:const http = require('http'); // or 'https' for https:// URLsconst fs = require('fs');const file = fs.createWriteStream("file.jpg");const request = http.get("http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg", function(response) { response.pipe(file);});如果你想支持在命令行上收集信息——比如指定目标文件或目录,或者 URL——检查类似 指挥官.If you want to support gathering information on the command line--like specifying a target file or directory, or URL--check out something like Commander. 这篇关于如何使用 Node.js 下载文件(不使用第三方库)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-03 21:02
查看更多