Node.js - How to get stream into string

user2316602 picture user2316602 · Jul 2, 2013 · Viewed 14.4k times · Source

I have got stream and I need to get stream content into string. I stream from internet using http.get. I also write stream into file, but I don't want to write file and after that open the same file and read from it... So I need to convert stream into string Thanks for all advices...

Answer

Sai Teja picture Sai Teja · Feb 3, 2016
var http = require('http');

var string = '';
var request = http.get("http://www.google.cz", function(response) {       
    response.on('data', function(response){
      string += response.toString();

  }); 
    response.on('end', function(string){
      console.log(string);
    });  
  });

This works for sure. I am using it.