title: How to modularize nodejs+expressjs code
body: <p>I've server.js as main file in my nodejs-expressjs application. In client side I am using angular js for templating(not using JADE/EJS on server side). I want to modularise this server.js file on the server as it may not be good if my application grows. </p>
  
  <pre><code>var express = require('express');
  var app = express();
  var fs = require("fs");
  
  /**
   *  Session
   */
  var session = require('express-session');
  app.use(session({secret: '!23',resave: false,saveUninitialized:false}));
  
  
  var bodyParser = require('body-parser');
  var mysql      = require('mysql');
  var async      = require('async');
  
  /**
   * Connect to MySQL
   */
  var config = require("./config");
  var db = config.database;
  var connection = mysql.createPool(db);
  
  app.use( bodyParser.json() );  
  
  // Create application/x-www-form-urlencoded parser
  var urlencodedParser = bodyParser.urlencoded({ extended: false });
  
  /**
   *  Provide web directory
   */
  app.use(express.static('public'));
  
  
  app.post('/abc', function (req, res) {
     //code 
  });
    app.post('/xyz', function (req, res) {
     //code 
  });
   app.post('/test', function (req, res) {
     //code 
  });
  var server = app.listen(config.port);
  </code></pre>
  
  <p>Suppose I want to add following method in seperate file lets say test.js. How would I do that?</p>
  
  <pre><code> app.post('/test', function (req, res) {
         //code 
      });
  </code></pre>