nodejs:routing using res.redirect not working showing 404 not found
<p>I am builing a web application using nodejs,express  and mongodb,and i am a beginer.
this is my app.js:</p>

<pre><code>var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var expressValidator=require('express-validator');
var expressSession=require('express-session');
var login = require('./routes/login');
var homepage = require('./routes/homepage');
var searchStudents=require('./routes/searchStudents');
var addStudents=require('./routes/addStudents');
var editStudents=require('./routes/editStudents');
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(expressValidator());
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
 app.use(expressSession({secret:'max',saveUninitialised:false,resave:false}));
app.use('/', login);
app.use('/homepage', homepage);
app.use('/homepage/SearchStudents',searchStudents);
app.use('/homepage/addStudents',addStudents);
app.use('/homepage/editStudents',editStudents);
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
if (app.get('env') === 'development') {
  app.use(function(err, req, res, next) {
  res.status(err.status || 500);
  res.render('error', {
  message: err.message,
  error: err
  });
 });
 }
 app.use(function(err, req, res, next) {
 res.status(err.status || 500);
 res.render('error', {
 message: err.message,
 error: {}
 });
 });
 module.exports = app;`
</code></pre>

<p>The my views have similar name to my routes.
I am able to redirect from login to homepage using post method
but i cant redirect from homepage to searchStudents.It show 404 error
Please help me with this routing problem.
this is my login.js:</p>

<pre><code>var express = require('express');
var router = express.Router();
var item;
var output=null;
var mongo =require('mongodb').MongoClient;
var assert=require('assert');
var url='mongodb://localhost:27016/test';
/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('login');

});
router.post('/hompage', function(req, res, next) {
    item={
        user:req.body.username,
        password:req.body.password
    };
    console.log("this is the username/// "+item.user);
    mongo.connect(url,function(err,db){
        assert.equal(null,err);
        result=db.collection('users').findOne({username:item.user},{id:0,password:0},function(err,data){
        if(err)
        {

            db.close();
            res.redirect('/');
        }
        else if(data==null)
        {
            db.close();
            res.redirect('/');
        }
        else
        {
            //console.log(data);
            db.close();
            res.redirect('/homepage');

        }

});
        });

});
</code></pre>

<p>this is my login.ejs</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;link rel='stylesheet' href='/stylesheets/style.css' /&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;h1 align="center"&gt;Login Page&lt;/h1&gt;
&lt;form action="/hompage" method="post"&gt;
&lt;table align="center"&gt;
&lt;tr&gt;
&lt;td&gt;&lt;i&gt;Enter Username&lt;/i&gt;
&lt;/td&gt;
&lt;td&gt;        
&lt;input type="text" name="username" placeholder="enter username"&gt;
&lt;/td&gt;   
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;i&gt;Enter Password&lt;/i&gt;&lt;/td&gt;
&lt;td&gt;    
&lt;input type="password" name="password" placeholder="enter password"&gt;
&lt;/td&gt;   
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;input type="submit" value="submit"&gt;
&lt;/td&gt;   
&lt;/tr&gt;       
&lt;/table&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>this is my homepage.js:</p>

<pre><code>var express = require('express');
var router = express.Router();
router.get('/', function(req, res, next) {
res.render('homepage');
});
router.post('/homepage/searchStudents', function(req, res, next) {
res.redirect('/homepage/searchStudents');
});
module.exports = router;
</code></pre>

<p>this is my homepage.ejs</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
 &lt;body&gt;
 &lt;h1&gt;homepage&lt;/h1&gt;
 &lt;form action="/homepage/searchStudents" method="post"&gt;
 &lt;input type="submit" value="Search Studetns"&gt;
 &lt;/form&gt;
 &lt;form action="/homepage/addStudents" method="post"&gt;
 &lt;input type="submit" value="Add Studetns"&gt;
 &lt;/form&gt;

 &lt;/body&gt;
 &lt;/html&gt;
</code></pre>