title: Is making sequential HTTP requests a blocking operation in node?
body: <p>Note that irrelevant information to my question will be 'quoted' </p>
  
  <blockquote>
    <p>like so (feel free to skip these).</p>
  </blockquote>
  
  <p><em>Problem</em></p>
  
  <p>I am using node to make in-order HTTP requests on behalf of multiple clients. This way, what originally took the client(s) several different page loads to get the desired result, now only takes a single request via my server. I am currently using the ‘async’ module for flow control and ‘request’ module for making the HTTP requests. There are approximately 5 callbacks which, using console.time, takes about ~2 seconds from start to finish (sketch code included below).</p>
  
  <blockquote>
    <p>Now I am rather inexperienced with node, but I am aware of the
    single-threaded nature of node. While I have read many times that node
    isn’t built for CPU-bound tasks, I didn’t really understand what that
    meant until now. If I have a correct understanding of what’s going on,
    this means that what I currently have (in development) is in no way
    going to scale to even more than 10 clients.</p>
  </blockquote>
  
  <p><em>Question</em></p>
  
  <p>Since I am not an expert at node, <strong>I ask this question (in the title) to get a confirmation that making several sequential HTTP requests is indeed blocking.</strong></p>
  
  <p><em>Epilogue</em></p>
  
  <p>If that is the case, I expect I will ask a different SO question (after doing the appropriate research) discussing various possible solutions, should I choose to continue approaching this problem in node (which itself may not be suitable for what I'm trying to do).</p>
  
  <p><em>Other closing thoughts</em></p>
  
  <p>I am truly sorry if this question was not detailed enough, too noobish, or had particularly flowery language (I try to be concise).</p>
  
  <p>Thanks and all the upvotes to anyone who can help me with my problem!</p>
  
  <p>The code I mentioned earlier:</p>
  
  <pre><code>var async = require('async');
  var request = require('request');
  
  ...
  
  async.waterfall([
      function(cb) {
          console.time('1');
  
          request(someUrl1, function(err, res, body) {
              // load and parse the given web page.
  
              // make a callback with data parsed from the web page
          });
      },
      function(someParameters, cb) {
          console.timeEnd('1');
          console.time('2');
  
          request({url: someUrl2, method: 'POST', form: {/* data */}}, function(err, res, body) {
              // more computation
  
              // make a callback with a session cookie given by the visited url
          });
      },
      function(jar, cb) {
          console.timeEnd('2');
          console.time('3');
  
          request({url: someUrl3, method: 'GET', jar: jar /* cookie from the previous callback */}, function(err, res, body) {
              // do more parsing + computation
  
              // make another callback with the results
          });
      },
      function(moreParameters, cb) {
          console.timeEnd('3');
          console.time('4');
  
          request({url: someUrl4, method: 'POST', jar: jar, form : {/*data*/}}, function(err, res, body) {
              // make final callback after some more computation.
              //This part takes about ~1s to complete
          });
      }
  ], function (err, result) {
      console.timeEnd('4'); //
      res.status(200).send();
  });
  </code></pre>