title: How does concurrency work in nodejs?
body: <p>I am trying to understand how concurrency works in a single-threaded environment like nodejs.</p>
  
  <p>Let's say I have this code:</p>
  
  <pre><code>var fs = require('fs');
  
  fs.readFile('file1', function one(err, data) {
    // some code...
  });
  
  fs.readFile('/file2', function two(err, data) {
    // some code...
  });
  </code></pre>
  
  <p>Now each <code>fs.readFile</code> call is async. So, they are running concurrently. But if all this is happening in a single thread, then how is the concurrency achieved? Are <code>function one</code> and <code>function two</code> running on the same or different thread? </p>
  
  <p>Basically, how does node.js handle concurrency?</p>