title: How to send error http response in express/node js?
body: <p>So in login page I am sending credentials from angular to express through get request.What I wanna do is that if found in database,send response and handle it in angular else if not found in db I want express to send error response and handle it angular error response function but my code isnt working.</p>
  
  <p>Angular controller:</p>
  
  <pre><code>myapp.controller('therapist_login_controller', ['$scope', '$localStorage', '$http',
    function($scope, $localStorage, $http) {
      $scope.login = function() {
        console.log($scope.username + $scope.password);
        var data = {
          userid: $scope.username,
          password: $scope.password
        };
        console.log(data);
        $http.post('/api/therapist-login', data)
          .then(
            function(response) {
              // success callback
              console.log("posted successfully");
              $scope.message = "Login succesful";
            },
            function(response) {
              // failure callback,handle error here
              $scope.message = "Invalid username or password"
              console.log("error");
            }
          );
      }
    }
  ]);
  </code></pre>
  
  <p>APP.js:</p>
  
  <pre><code>  app.post('/api/therapist-login', therapist_controller.login);
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>  module.exports.login = function(req, res) {
  
      var userid = req.body.userid;
      var password = req.body.password;
      console.log(userid + password);
  
      Credentials.findOne({
        'userid': [userid],
        'password': [password]
      }, function(err, user) {
        if (!user) {
          console.log("logged err");
          res.status(404); //Send error response here
          enter code here
        } else {
          console.log("login in");
        }
      });
    }
  </code></pre>