title: non-blocking node.js express web server
body: <p>Maybe this is a possible duplicate, but even after reading many questions here on stackoverflow, i still cant find a explanation for my problem.
  My problem/question in general is, how nodejs and special express.js is handling parallel http requsts without blocking. Below you can find a short example that represents the problem:</p>
  <pre><code>var express = require(&quot;express&quot;);
  var app = express();
  
  const PORT = 4003;
  
  
  var server = app.listen(PORT);
  console.log(&quot;Server running at http://127.0.0.1:&quot; + PORT + &quot;/&quot;);
  
  app.get('/threadtest/request1', sendResponse1);
  
  app.get('/threadtest/request2', sendResponse2);
  
  async function sendResponse1(req, res){
      await waitSomeTime2();
      res.send(&quot;done waiting&quot;);
  }
  
  
  function sendResponse2 (req, res){
      res.send('Hello2');
  }
  
  const waitSomeTime = () =&gt; new Promise((resolve) =&gt;{
      setTimeout(() =&gt; resolve(), 5000);
  });
  
  const waitSomeTime2 = () =&gt; new Promise((resolve) =&gt;{
      calculate(() =&gt; resolve());
  });
  
  async function calculate(){
      var i = 0;
      for(i = 0; i &lt; 10000000000; i++){
      }
      return i.toString();
  }
  </code></pre>
  <p>The webserver works fine as long there are no tasks that need some calculation time. For testing purposes, i added the <code>calculate</code> function (in the real application this is some kind of parsing the request and a database request).</p>
  <p>When i directly called <code>calculate()</code> in the <code>sendResponse1</code> function, the server could not handle any other requests until <code>calculate</code> was done and the response send. My first attempt was using an async function as a callback, but that did not change anything. The server is still blocked.</p>
  <p>After some googling i found the codesnippet called <code>waitSomeTime</code> here on stackoverflow. Calling this after the <code>await</code> in <code>sendResponse1</code> works as expected. The response to a get-request at request1 delays about 5 seconds but the server can handle other request while waiting.
  To be honest, i dont fully understand what exactly happens in waitSomeTime but i tried to integrate my calculate function, but now the server is blocked again.</p>
  <p>The aproach to make the handler function async seems correct to me, (i have seen this many times so far) but i can´t find a way to make the calculate function non-blocking. I did not use async/await this much so far, so please excuse if i did somthing fundamental wrong. Maybe someone can help me with this or explain how this is done correctly. As said, the calculate function is only a dummy load but the goal is, that the server is not blocking other request if one of them takes way longer.</p>
  <p>Thanks in advance</p>