I am trying to send status response codes from the backend which is in Node.js to my frontend which is in Angular in order to display an error message "Email already exists".

// Frontend 

```
add.user.component.ts

 if (this.AddUserForm.valid) {
      this.AuthService.register(this.AddUserForm.value)
      .pipe(first())
      .subscribe(
        data => {
            this.router.navigate(['dashboard/user']);
          this.snackbar.open('User has been Added', 'Close', {
            duration: 3000,
          });
        },
        error => {
          this.loading = false;
          this.snackbar.open('Unsuccessful', 'Close', {
            duration: 3000,
          });
        },
      );
    } 

```

authentication.service.ts

```
register(user: User) {
    // const headers = new HttpHeaders({ 'Authorization': JSON.parse(localStorage.getItem('currentUser')).token });
    return this.http.post<any>(`${this.environment.userUrl}/auth/register`, user);
  }

```

// Backend

authentication.js

```
exports.register = function (req, res, next) {

    var email = req.body.email;
    var password = generator.generate({
        length: 10,
        numbers:true,
        uppercase:true,
        symbols: true
    });

    if (!email) {
        return res.status(422).send({
            error: 'You must enter an email address'
        });
    }

    User.findOne({
        email: email
    }, function (err, existingUser) {

        if (err) {

            return next(err);
        }

        if (existingUser) {
            return res.status(422).send({
                error: 'That email address is already in use'
            });
        }

        var user = new User({
            email: email,
             password: password,

        });

        user.save(function (err, user, done) {

            if (err) {
                return next(err);
            }

            var userInfo = setUserInfo(user);

            res.status(201).json({
                message: 'Please Check you Email Address',
                 token: 'JWT ' + generateToken(userInfo),
                user: userInfo
            });

```

The response code needs to be sent from the backend to my frontend. Here, in this case, response status code 422 needs to be sent to my frontend