How to download a file with Node.js (without using third-party libraries)?

后端 未结 28 1752
逝去的感伤
逝去的感伤 2020-11-22 03:37

How do I download a file with Node.js without using third-party libraries?

I don\'t need anything special. I only want to download a file from a giv

28条回答
  •  轮回少年
    2020-11-22 04:08

    Path : img type : jpg random uniqid

        function resim(url) {
    
        var http = require("http");
        var fs = require("fs");
        var sayi = Math.floor(Math.random()*10000000000);
        var uzanti = ".jpg";
        var file = fs.createWriteStream("img/"+sayi+uzanti);
        var request = http.get(url, function(response) {
      response.pipe(file);
    });
    
            return sayi+uzanti;
    }
    

提交回复
热议问题