Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk3 min

How to Serve an Angular App Locally for Development

Use ng serve to compile and run an Angular CLI app locally, watch code changes, and optionally proxy API requests to a local backend.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To run an Angular CLI app locally, open a terminal in its workspace and run ng serve. The command builds the app for development, starts a local server—by default at http://localhost:4200/—and rebuilds and reloads the page as you change code. Press Ctrl+C to stop it.

What ng serve does

Angular’s documentation, “Serving Angular apps for development,” says: “You can serve your Angular CLI application with the ng serve command.” The command runs the workspace project’s configured serve target. If you omit the project name, the CLI uses the workspace’s default project. It compiles the app, starts a development server, and watches for code changes so it can rebuild and live reload.

The command can also be written as ng dev or ng s. Run it from an Angular CLI workspace, typically the directory containing angular.json. If the command is unavailable, confirm that you are in the workspace and that its dependencies are installed.

Run the app and choose local server options

Start with:

ng serve

The current Angular CLI reference lists localhost as the default host and 4200 as the default port. Useful options include:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Need Option Example
Use a different port --port ng serve --port 4300
Set the host interface --host ng serve --host 0.0.0.0
Open the app in a browser --open ng serve --open
Enable or disable file watching --watch ng serve --watch=false
Control live reload --live-reload ng serve --live-reload=false
Enable hot module replacement --hmr ng serve --hmr
Select a named configuration --configuration ng serve --configuration development
Load an API proxy file --proxy-config ng serve --proxy-config proxy.conf.json
Use HTTPS --ssl ng serve --ssl

The current CLI reference lists watching and live reload as enabled by default, with HMR defaulting to the live-reload setting. Options and defaults can differ between CLI versions, so check the installed version’s help with ng serve --help.

Check the project’s serve target

The behavior of ng serve comes from the project’s serve target in angular.json. Look under projects, select the relevant project, then inspect architect.serve (some workspace files use targets). The target identifies a builder and can define options and named configurations; it can also reference a particular build target.

@angular/build:dev-server is the common builder in current Angular projects. Older or migrated workspaces may instead use @angular-devkit/build-angular:dev-server. Do not assume every workspace has the same behavior: the configured builder and its version matter, especially for proxy rules and HMR.

Connect the app to a local API

A development proxy lets browser requests to an app-relative path such as /api be forwarded to a local backend, avoiding the need to hard-code the backend host into each request. Angular’s proxy example routes requests to http://localhost:3000.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Create a proxy configuration file, for example proxy.conf.json:
{
  "/api/**": {
    "target": "http://localhost:3000",
    "secure": false
  }
}
  1. Either add "proxyConfig": "proxy.conf.json" to the project’s serve options in angular.json, or pass the file when starting the server:
ng serve --proxy-config proxy.conf.json
  1. Have the Angular app call a relative URL such as /api/users. Start the backend separately, then test the request through the Angular app.
  2. If you edit the proxy configuration while the server is running, stop and restart ng serve; the changed proxy file is not applied until restart.

Proxy path matching depends on the builder

For the Vite-based @angular/build:dev-server, the patterns differ in scope: /api matches only the base path, /api/* matches one path segment, and /api/** matches nested paths. For the Webpack-based @angular-devkit/build-angular:dev-server, /api matches the base route and its subpaths. A proxy rule that worked before a builder migration may therefore need adjustment.

Development serving is not production deployment

ng serve uses the development configuration by default. Angular’s development configuration can include checks, detailed errors, and debugging helpers. Use the development server for local iteration; it is not the command for generating deployable production output.

For a production build, run:

ng build

Angular documents that ng build uses the production configuration by default and removes development-only code from the output. A project’s angular.json can define or override configurations, so inspect its build and serve targets when the behavior differs from these defaults.

Keep secrets out of environment files

Angular environment files can select client-visible settings such as an API base URL for different configurations. Their contents are bundled into the browser application and can be seen by anyone who loads it. Do not put API keys, passwords, or other secrets in them. Keep secrets on a server, and have the app make requests through a backend or another server-side secrets-management approach.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When to use HMR

The current CLI reference exposes --hmr, and its default follows the live-reload setting. HMR behavior depends on the builder and Angular CLI generation. Angular’s build-system migration documentation describes hot replacement of component templates and styles in its documented build-system workflow; do not assume identical HMR support in every older workspace. If ordinary live reload meets your needs, no HMR option is required.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.