title: How to split Node.js files in several files
body: <p>I have this code:</p>
  
  <pre><code>var express = require("express");
  var app     = express();
  var path    = require("path");
  
  app.use(express.static(__dirname + '/public'));
  
  app.get('/',function(req,res){
    res.sendFile(path.join(__dirname+'/views/index.html'));
    res.set('Access-Control-Allow-Origin', '*');
  }).listen(3000);
  
  console.log("Running at Port 3000");
  
  app.get('/test', function(req, res) {
      res.json(200, {'test': 'it works!'})
  })
  </code></pre>
  
  <p>I will have many services (like the <code>test</code> one), and I don't want to have them all on the same file.</p>
  
  <p>I read in another question in Stack Overflow, that I can require other files like this: <code>var express = require("./model/services.js");</code> And in that file write all the services, but it's throwing <code>app is not defined</code> when I start Node.</p>
  
  <p>How can I separate codes?</p>