title: expressjs router not working
body: <p>I am new to MEAN stack, so i am going through tutorials and it pretty clear that not all people use same logic.
  But now i am stuck on these two examples </p>
  
  <p>Example One</p>
  
  <pre><code>// server.js
  var express = require('express'),
      app = express(),
      port = 1337;
  // indicating view folder
  app.set('views', './views');
  // indicating view engine
  app.set('view engine', 'ejs');
  // adding routes
  require('./routes/index.js')(app);
  require('./routes/user.js')(app);
  //
  app.listen(port);
  module.exports = app;
  
  
  ./routes/index.js
  module.exports = function(app) {
      // show indix view
      app.get('/', function(req, res) {
              res.render('index', {
                  title: 'Index page',
              });
      });
  };
  </code></pre>
  
  <p>above we are using <code>get</code> method from <code>app</code> (which is instance of <code>express</code>)</p>
  
  <pre><code>./routes/user.js
  module.exports = function(app) {
      // showing user page
      app.route('/users').get(function(req, res) {
              res.render('user', {
                  title: 'User page'
              });
      });
  };
  </code></pre>
  
  <p>above we are using <code>route</code> method of <code>express</code> and then bind <code>get</code> to it</p>
  
  <p>so when the app is running, and i access <code>localhost:1337</code> index page is called
  and when <code>localhost:1337/user</code> is called user page is called</p>
  
  <p>Example two
  Now when we use <code>express myapp</code> command, this example has some different logic</p>
  
  <p>we have main <code>app.js</code></p>
  
  <pre><code>var express = require('express');
  
  var routes = require('./routes/index');
  var users = require('./routes/users');
  
  var app = express();
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  
  app.use('/', routes);
  app.use('/users', users);
  
  app.listen(1337);
  
  module.exports = app;
  </code></pre>
  
  <p>As you can see first we require <code>index</code> and <code>user</code> route files required
  and then we use <code>app.use</code> command to set routes.</p>
  
  <p>in <code>./routes/index.js</code> file</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  /* GET home page. */
  router.get('/', function(req, res, next) {
    res.render('index', { title: 'Express' });
  });
  
  module.exports = router;
  </code></pre>
  
  <p>we get method <code>router</code> of <code>express</code> and then bind <code>get</code> method to it</p>
  
  <p>so my question is, when i commit <code>app.use('/', routes);</code> and call <code>localhost:1337</code> i get error
  but we have already using router in <code>./routes/index.js</code> to show index page. 
  this should work according to first example. </p>
  
  <p>EDIT error msg</p>
  
  <pre><code>Error: Not Found
      at app.use.res.render.message (/home/vagrant/meanstack/myapp/app.js:30:15)
      at Layer.handle [as handle_request] (/home/vagrant/meanstack/myapp/node_modules/express/lib/router/layer.js:82:5)
      at trim_prefix (/home/vagrant/meanstack/myapp/node_modules/express/lib/router/index.js:302:13)
      at /home/vagrant/meanstack/myapp/node_modules/express/lib/router/index.js:270:7
      at Function.proto.process_params (/home/vagrant/meanstack/myapp/node_modules/express/lib/router/index.js:321:12)
      at next (/home/vagrant/meanstack/myapp/node_modules/express/lib/router/index.js:261:10)
      at SendStream.error (/home/vagrant/meanstack/myapp/node_modules/express/node_modules/serve-static/index.js:107:7)
      at SendStream.emit (events.js:95:17)
      at SendStream.error (/home/vagrant/meanstack/myapp/node_modules/express/node_modules/send/index.js:244:17)
      at SendStream.onStatError (/home/vagrant/meanstack/myapp/node_modules/express/node_modules/send/index.js:340:48)
  </code></pre>
  
  <p>i had this code to handle error</p>
  
  <pre><code>app.use(function(req, res, next) {
      var err = new Error('Not Found');
      err.status = 404;
      next(err);
  })
  </code></pre>
  
  <p>now when i comment this code and comment  <code>app.use('/', routes);</code> and run the server.js</p>
  
  <p>i get this when i run <code>localhost:1337</code></p>
  
  <pre><code>Cannot GET / 
  </code></pre>
  
  <p>if you still cannot see the error, try <code>express app</code> in folder and create a new file <code>server.js</code> and add below code and run <code>node server.js</code></p>
  
  <pre><code>var express = require('express');
  var path = require('path');
  var routes = require('./routes/index');
  var users = require('./routes/users');
  
  var app = express();
  
  // view engine setup
  app.set('views', path.join(__dirname, 'views'));
  app.set('view engine', 'jade');
  
  //app.use('/', routes);
  app.use('/users', users);
  
  app.listen(1337);
  
  module.exports = app;
  console.log(" call 192.168.33.33:1337");
  </code></pre>