title: Dependency Injection in Node.js
body: <p>I'm reading this nice tutorial about Node.js web servers: <a href="http://nodebeginner.org/" rel="nofollow">http://nodebeginner.org/</a>
  In this part of the tutorial: <a href="http://nodebeginner.org/#whats-needed-to-route-requests" rel="nofollow">http://nodebeginner.org/#whats-needed-to-route-requests</a> they show how to do something called 'injection dependencies' in order to link both the <strong>route</strong> module and the <strong>server</strong> module to the main js file <strong>index.js</strong>.</p>
  
  <p>I've tried exactly what they write there, but the computer won't like this. It shows me an error message:  <em>route is not defined</em>'.
  I don't know what to do, please help me with this..I'm pretty new to Node.js and have never seen this kind of dependency injection before.<br>
  Thank you!  </p>
  
  <p>Here is the contents of index.js:  </p>
  
  <pre><code>var server = require("./myHttp");
  var router = require("./router");
  
  server.start(router.route);
  </code></pre>
  
  <p>Here is the myHttp.js file:  </p>
  
  <pre><code>var http = require("http");
  var url = require("url");
  
  function start(){
  function onRequest(request, response) {
    var pathname = url.parse(request.url).pathname;
    console.log("Request for "+ pathname + " recieved.");
  
    route(pathname);
  
    response.writeHead(404, {"Content-Type": "text/plain"});
    response.write("Hello World");
    response.end();
  }
  
  http.createServer(onRequest).listen(8888);
  console.log("Server has started.");
  }
  
  exports.start = start;  
  </code></pre>
  
  <p>Here is the router.js file:  </p>
  
  <pre><code>function route(pathname) {
  console.log("About to route a request for " + pathname);
  }
  
  exports.route = route;  
  </code></pre>
  
  <p>I run the following command in the cmd: <strong>node index.js</strong></p>