Read remote file with node.js (http.get)

后端 未结 4 1534
野趣味
野趣味 2020-11-29 05:26

Whats the best way to read a remote file? I want to get the whole file (not chunks).

I started with the following example

var get = http.get(options)         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 06:29

    http.get(options).on('response', function (response) {
        var body = '';
        var i = 0;
        response.on('data', function (chunk) {
            i++;
            body += chunk;
            console.log('BODY Part: ' + i);
        });
        response.on('end', function () {
    
            console.log(body);
            console.log('Finished');
        });
    });
    

    Changes to this, which works. Any comments?

提交回复
热议问题