title: Node.JS - fs.exists not working?
body: <p>I'm a beginner in Node.js, and was having trouble with this piece of code. </p>
  
  <pre><code>var fs = require('fs');
  
  Framework.Router = function() {
  
      this.run = function(req, res) {
          fs.exists(global.info.controller_file, function(exists) {
              if (exists) {
                              // Here's the problem
                              res.writeHead(200, {'Content-Type':'text/html'});
                  var cname = App.ucfirst(global.info.controller)+'Controller';
                  var c = require(global.info.controller_file);
                  var c = new App[cname]();
                  var action = global.info.action;
                  c[action].apply(global.info.action, global.info.params);
                              res.end();
              } else {
                  App.notFound();
                  return false;
              }
          });
      }
  };
  </code></pre>
  
  <p>The problem lies in the part after checking if the 'global.info.controller_file' exists, I can't seem to get the code to work properly inside the: if (exists) { ... <strong>NOT WORKING</strong> }
  I tried logging out the values for all the variables in that section, and they have their expected values, however the line: <code>c[action].apply(global.info.action, global.info.params);
  </code> is not running as expected. It is supposed to call a function in the controller_file and is supposed to do a simple <code>res.write('hello world');</code>. I wasn't having this problem before I started checking for the file using <code>fs.exists</code>. <strong>Everything inside the if statement, worked perfectly fine before this check.</strong> </p>
  
  <p>Why is the code not running as expected? Why does the request just time out?
  Does it have something to do with the whole synchronous vs asynchronous thing? (Sorry, I'm a complete beginner)</p>
  
  <p>Thank you</p>