title: Node.js - Loading Files in Runtime
body: <p>I'm fairly new to Node.js and am having trouble understanding the way to go about loading libraries or files, in <strong>runtime</strong>. 
  Apparently, it is a bad idea to load files in runtime using Node.js's native "require" function because it is blocking i/o, and therefore should not be used from within request handlers. So, I'm assuming something like this is to be avoided:</p>
  
  <pre><code>var http = require('http').createServer(function(req, res) { 
    var file = require('./pages/'+req.url);
    res.end();
  }).listen(8080);
  </code></pre>
  
  <p><strong>So then is there a way to require files in runtime, in a non-blocking/asynchronous way?</strong> </p>
  
  <p>I don't think it would always be possible to load files in "boot time" rather than runtime because like in the example above, the only way to know what file to load/require is by getting the name through the <code>req.url</code> property. </p>
  
  <p>So that seems like the only option. Unless, all the files in the folder are preloaded and then called upon by name, in the callback (By using <code>fs.readdirSync</code> or something to iterate through all the files in the folder and compare the gotten files' names to the <code>req.url</code> property), but that seems wasteful. "Preloading" all the files in the folder (maybe around 50 files) and then only using 1 of them, doesn't seem like a good idea. Am I wrong?</p>
  
  <p>Either way, I would just like to know if there is a way to require files in runtime in a better, non-blocking/asynchronous way.</p>
  
  <p>Thank you!</p>