title: NodeJS + ExpressJS: What is routes/index.js and its purpose?
body: <p>What is the purpose of this file? </p>
  
  <p>Is this where 'all' the get and post calls get instantiated?</p>
  
  <p>If so, wouldn't this be a very huge file when working with large scale projects?</p>
  
  <p>I've tried calling a post, /authenticateLogin, from another file other than routes/index.js, but it fails to work, resulting in a 404 error.</p>
  
  <p><strong>routes/login.js</strong></p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  router.get('/', function(req, res) {
      res.render('login');
  });
  
  router.post('/authenticateLogin', function(req, res){
      console.log("Authenticating 2!");
      res.send('number two!');
  });
  
  module.exports = router;
  </code></pre>
  
  <p>But it works perfectly when I put it in the index.js file.</p>
  
  <p><strong>routes/index.js</strong></p>
  
  <pre><code>var express = require('express');
  var router  = express.Router();
  
  router.get('/', function(req, res) {
      res.render('index', { title: 'Home' });
  });
  
  router.post('/authenticateLogin', function(req, res){
      console.log("Authenticating 1!");
      res.send('number one!');
  });
  
  module.exports = router;
  </code></pre>
  
  <p><strong>views/login.jade</strong></p>
  
  <pre><code>extends layout
  
  block content
  h1 Login 
  
  form(method='post' action='/authenticateLogin')
      input(type='text' placeholder='username' name='username')
      input(type='password' placeholder='password' name='password')
  
      input(type='submit')
  </code></pre>