# Angular CLI: [HPM] Error occurred while proxying request localhost:4200 to http://localhost:3000 [ECONNREFUSED]

**Code:** `proxy.conf.json not working` · **Category:** Angular · **Seen on:** Angular, Angular CLI

The `ng serve` dev proxy cannot forward your API call — it was not enabled, the path does not match, or the target server is down.

## Meaning

Add `--proxy-config proxy.conf.json` (or set `proxyConfig` in angular.json) and restart `ng serve`; the file is read only at start. Paths must match the request URL prefix, and the target must be reachable. HPM errors like ECONNREFUSED mean the back end is not listening; 404 means the path rewrite is wrong.

## Common causes

- `ng serve` started without `--proxy-config` / `proxyConfig`
- Dev server not restarted after editing the file
- Request path does not start with the configured prefix (`/api`)
- Back-end target not running or wrong port (ECONNREFUSED)
- HTTPS target with self-signed certificate needs `secure: false`

## Quick fix

1. Start with `ng serve --proxy-config proxy.conf.json`
2. Make sure the API is running on the target port
3. Use relative URLs (`/api/users`) in the app

## Detailed fix by platform

### Angular CLI

1. In angular.json: `"serve": { "options": { "proxyConfig": "proxy.conf.json" } }`
2. Debug with `"logLevel": "debug"` in the proxy entry

## Code examples

### Path rewrite

```json
{
  "/api": {
    "target": "http://localhost:3000",
    "secure": false,
    "changeOrigin": true,
    "pathRewrite": { "^/api": "" },
    "logLevel": "debug"
  }
}
```

## How to diagnose

1. **Enabled** — Is proxyConfig set and the server restarted?
2. **Match** — Does the request start with the prefix?
3. **Target** — Is the API listening?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/angular/proxy-conf-json-not-working)
