当前位置:网站首页>Node fetch download file

Node fetch download file

2022-06-23 00:45:00 Ziwei front end

var fetch = require("node-fetch");
var fs = require("fs");

function download(u, p) {
    return fetch(u, {
        method: 'GET',
        headers: { 'Content-Type': 'application/octet-stream' },
    }).then(res => res.buffer()).then(_ => {
        fs.writeFile(p, _, "binary", function (err) {
            console.log(err || p);
        });
    });
}
======= 
var url = "https://nodejs.org/dist/v8.9.4/node-v8.9.4-win-x64.zip";
download(url, url.split("/").reverse()[0])

原网站

版权声明
本文为[Ziwei front end]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206222049583023.html