title: GET http://localhost:8000/api net::ERR_CONNECTION_REFUSED
body: <p>I am Making a angular project to show, add, delete, and updated an employees details. I have an api i made myself connected but i keep getting the same error when i try to post or get the list of Employees. I am using Angular, Express, Node, and Mongodb. Any help would be greatly appricated. I am not sure what code to put up to make it easier for the help but i can put up the errors.enter image description here</p>
  <p><a href="https://i.stack.imgur.com/iSifV.jpg" rel="nofollow noreferrer">Get Error</a></p>
  <p><a href="https://i.stack.imgur.com/Phzxg.jpg" rel="nofollow noreferrer">Error</a></p>
  <p><a href="https://i.stack.imgur.com/3KUhC.jpg" rel="nofollow noreferrer">Post Error</a></p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import { Injectable } from '@angular/core';
  import { Employee } from './Employee';
  import { catchError, map } from 'rxjs/operators';
  import { Observable, throwError } from 'rxjs';
  import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
   
  @Injectable({
    providedIn: 'root'
  })
   
  export class CrudService {
   
    // Node/Express API
    REST_API: string = 'http://localhost:8000/api';
   
    // Http Header
    httpHeaders = new HttpHeaders().set('Content-Type', 'application/json');
    router: any;
   
    constructor(private httpClient: HttpClient) { }
   
    // Add
    AddEmployee(data: Employee): Observable&lt;any&gt; {
      let API_URL = `${this.REST_API}/add-employee`;
      return this.httpClient.post(API_URL, data)
        .pipe(
          catchError(this.handleError)
        )
    }
   
    // Get all objects
    GetEmployees() {
      return this.httpClient.get(`${this.REST_API}`);
    }
   
    // Get single object
    GetEmployee(id:any): Observable&lt;any&gt; {
      let API_URL = `${this.REST_API}/read-employee/${id}`;
      return this.httpClient.get(API_URL, { headers: this.httpHeaders })
        .pipe(map((res: any) =&gt; {
            return res || {}
          }),
          catchError(this.handleError)
        )
    }
   
    // Update
    updateEmployee(id:any, data:any): Observable&lt;any&gt; {
      let API_URL = `${this.REST_API}/update-employee/${id}`;
      return this.httpClient.put(API_URL, data, { headers: this.httpHeaders })
        .pipe(
          catchError(this.handleError)
        )
    }
   
    // Delete
    deleteEmployee(id:any): Observable&lt;any&gt; {
      let API_URL = `${this.REST_API}/delete-employee/${id}`;
      return this.httpClient.delete(API_URL, { headers: this.httpHeaders}).pipe(
          catchError(this.handleError)
        )
    }
   
   
    // Error 
    private handleError(error: Response | any) {
      let errorMessage = '';
      if (error.status == 0) {
        // Handle client error
        errorMessage = error.error.message;
        this.router.navigate(['/error'])
      } else {
        // Handle server error
        errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
      }
      console.log(errorMessage);
      return throwError(errorMessage);
    }
   
  }</code></pre>
  </div>
  </div>
  </p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>import { Injectable } from '@angular/core';
  import { Employee } from './Employee';
  import { catchError, map } from 'rxjs/operators';
  import { Observable, throwError } from 'rxjs';
  import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
   
  @Injectable({
    providedIn: 'root'
  })
   
  export class CrudService {
   
    // Node/Express API
    REST_API: string = 'http://localhost:8000/api';
   
    // Http Header
    httpHeaders = new HttpHeaders().set('Content-Type', 'application/json');
    router: any;
   
    constructor(private httpClient: HttpClient) { }
   
    // Add
    AddEmployee(data: Employee): Observable&lt;any&gt; {
      let API_URL = `${this.REST_API}/add-employee`;
      return this.httpClient.post(API_URL, data)
        .pipe(
          catchError(this.handleError)
        )
    }
   
    // Get all objects
    GetEmployees() {
      return this.httpClient.get(`${this.REST_API}`);
    }
   
    // Get single object
    GetEmployee(id:any): Observable&lt;any&gt; {
      let API_URL = `${this.REST_API}/read-employee/${id}`;
      return this.httpClient.get(API_URL, { headers: this.httpHeaders })
        .pipe(map((res: any) =&gt; {
            return res || {}
          }),
          catchError(this.handleError)
        )
    }
   
    // Update
    updateEmployee(id:any, data:any): Observable&lt;any&gt; {
      let API_URL = `${this.REST_API}/update-employee/${id}`;
      return this.httpClient.put(API_URL, data, { headers: this.httpHeaders })
        .pipe(
          catchError(this.handleError)
        )
    }
   
    // Delete
    deleteEmployee(id:any): Observable&lt;any&gt; {
      let API_URL = `${this.REST_API}/delete-employee/${id}`;
      return this.httpClient.delete(API_URL, { headers: this.httpHeaders}).pipe(
          catchError(this.handleError)
        )
    }
   
   
    // Error 
    private handleError(error: Response | any) {
      let errorMessage = '';
      if (error.status == 0) {
        // Handle client error
        errorMessage = error.error.message;
        this.router.navigate(['/error'])
      } else {
        // Handle server error
        errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`;
      }
      console.log(errorMessage);
      return throwError(errorMessage);
    }
   
  }</code></pre>
  </div>
  </div>
  </p>