Promises with http.get node.js
<p>Im am doing nodeschool exercises , the </p>

<blockquote>
  <p>This problem is the same as the previous problem (HTTP COLLECT) in
  that you need to use http.get(). However, this time you will be
  provided with three URLs as the first three command-line arguments.</p>
  
  <p>You must collect the complete content provided to you by each of the
  URLs and print it to the console (stdout). You don't need to print out
  the length, just the data as a String; one line per URL. The catch is
  that you must print them out in the same order as the URLs are
  provided to you as command-line arguments.</p>
</blockquote>

<p>in other words , i am to register 3 http.get request , and print data recieved from it in order.</p>

<p>I am trying to do it with promises = another get request wont be called untill the first on didnt end.</p>

<p>My code looks like this </p>

<pre><code>var http=require("http");
var collect=[];
var dat=[];
for( var i = 2 ; i &lt; process.argv.length;i++){
    collect.push(process.argv[i]);
}

function chainIt(array,callback){
    return array.reduce(function(promise,item){
        return promise.then(function(){
            return callback(item)
        })
    },Promise.resolve())
}



function getIt(item){
    return http.get(item,function(response){
        response.on("data",function(data){
                dat.push(data);
        })

    })
}


chainIt(collett,function(item){
    return getIt(item)
    })
}).then(function(){
    collect.forEach(function(x){
            console.log(x);
    })

})
</code></pre>

<p>But i actually print no data = i fail the exercise.</p>

<p>I do not see any bug here  , but im just starting with promises and node. Where is the mistake?</p>