When the user is validated the client get the page contents of home.html in result instead of redirecting to the home.html.
Client side call:
$http({ method: "post", url: "http://localhost:2222/validateUser", data: { username: $scope.username, password: $scope.password } }).then(function (result) { if (result.data && result.data.length) { alert('User validated'); } else { alert('invalid user'); } }); Server side controller method:
module.exports.validateUser = function (req, res) { User.find({ 'username': req.body.username, 'password': req.body.password }, function (err, result) { if (result.length) { req.session.user = result[0]._doc; res.redirect('/home'); }else{ res.json(result); } }); }; Route in app.js:
app.get('/home', function (req, res) { var path = require('path'); res.sendFile(path.resolve('server/views/home.html')); });