How to send error http response in express/node js?

In Node with ExpressJS you can use res.status() to send the error:

return res.status(400).send({
   message: 'This is an error!'
});

In Angular you can catch it in the promise response:

$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
            // response.data.message will be "This is an error!"

            console.log(response.data.message);

            $scope.message = response.data.message
        }
    );

Leave a Comment

404 Not Found

Not Found

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.