localhost:4200
Port 4200 means one thing: Angular. Every Angular CLI project runs ng serve and opens on 4200. It's been Angular's home since AngularJS became Angular 2+ and the CLI became the standard way to develop.
Quick Start
# Create new Angular project
ng new my-app
cd my-app
ng serve
# Output:
# ** Angular Live Development Server is listening on localhost:4200
# Open your browser on http://localhost:4200/
Change Angular Port
# Command line
ng serve --port 3000
# Or in angular.json
"serve": {
"options": {
"port": 3000
}
}
Proxy API Requests
Angular app on 4200, backend on 3000? Set up a proxy:
// proxy.conf.json
{
"/api": {
"target": "http://localhost:3000",
"secure": false
}
}
// Run with proxy
ng serve --proxy-config proxy.conf.json
Common Issues
| Problem | Solution |
|---|---|
| Port 4200 in use | ng serve --port 4201 |
| Live reload not working | Check WebSocket, try --poll |
| CORS errors | Use proxy config for API calls |
| Slow compilation | Upgrade Angular CLI, check memory |
Useful ng serve Flags
ng serve --open # Auto-open browser
ng serve --host 0.0.0.0 # Allow network access
ng serve --ssl # Enable HTTPS
ng serve --configuration production # Prod mode