Devacron.com

Nodeschool.io – Http Client and Http Collect

<p]]>Below you can find my solutions to Nodeschool.io exercises “HTTP Client” and “HTTP Collect”.  In the first one you have to use the http core module. The code is simple enough: 

var http = require("http");
http.get(process.argv[2], function(response){
	response.setEncoding("utf8")
	response.on("data", function(data){
		console.log(data);
	})
});

And my solution for http collect uses the bl module. You can install it like this : npm install bl

var http = require("http");
const BufferList = require('bl')
var bl = new BufferList()
http.get(process.argv[2], function(response){
	response.on("data", function(data){
		bl.append(data)
	})

	response.on("end",function(){
		console.log(bl.length)
		console.log(bl.toString())			
	})	
})
Exit mobile version