title: How do I redirect user to 'home' page after validating his login data with database?
body: <p>After checking login data (user name and password) I would like to redirect the valid user to home page.</p>
  
  <p>Here is app. post:</p>
  
  <pre><code>    app.post('/', function ( req , res) {
  
      req.checkBody('home_user_name', 'User Name is required').notEmpty();
      req.checkBody('home_password', 'Password is required').notEmpty();
  
  
  pool.getConnection(function (error, tempCont) {
                  if (!!error) {
          tempCont.release();
                      console.log('Error');
                  }
                  else {
                      console.log('Connected!');
  
  
                  function get_role(callback) {
  
  
           console.log("look here &gt;&gt; " + req.body.home_user_name);
  </code></pre>
  
  <p>here is query:</p>
  
  <pre><code>   tempCont.query('SELECT * from `users` where `user_name` = ? ', [req.body.home_user_name] , function (error, results) {
                      if (error) callback(null);
                      callback(results[0].password);
                  });
              }
  </code></pre>
  
  <p>here is the question how to redirect the valid user to home page? note that it is a function inside function inside app.post: </p>
  
  <pre><code> get_role(function (data) {
                      if (data == req.body.home_password){
  
  
                      console.log("User Name is " + req.body.home_user_name + " and Password is " + data);
                   }
                      else {
                          console.log("passwords are not identical ");
                      }
                  }
                  );
  </code></pre>
  
  <p>here is errors validation:</p>
  
  <pre><code>   var errors = req.validationErrors();
              if (errors) {
                  res.render('app', { errors: errors });
              } else {
                  console.log("Validation: " + req.body.home_user_name);
              }
          }
      })
      })
  </code></pre>