Starting the Development Server
The easiest way to start the application is using the Angular CLI:ng serve which starts the Angular development server.
The development server uses the
development configuration by default, which includes source maps and disables optimization for faster builds.Accessing the Application
Once the server is running, you can access the application at:Available Scripts
The following npm scripts are available inpackage.json:
Development Scripts
start
Starts the development server on port 4200
build
Builds the application for production
watch
Builds and watches for changes in development mode
test
Runs unit tests with Karma and Jasmine
Script Details
npm start or ng serve
- Starts the development server
- Enables hot module replacement (HMR)
- Runs on http://localhost:4200
- Uses development configuration (unoptimized, with source maps)
npm run build
- Creates a production build
- Optimizes and minifies code
- Outputs to
dist/directory - Enables output hashing for cache busting
- Enforces bundle size budgets (500kB warning, 1MB error for initial bundle)
npm run watch
- Continuously builds the application
- Watches for file changes
- Uses development configuration
- Useful for testing build output without running the dev server
npm test
- Launches Karma test runner
- Runs all
*.spec.tsfiles - See Testing for more details
Hot Reload
The development server includes hot module replacement (HMR) functionality:- Automatic Reload: When you save changes to any source file, the application automatically reloads
- Fast Refresh: Most changes are reflected within 1-2 seconds
- Preserved State: In many cases, application state is preserved during reload
Port Configuration
By default, the application runs on port 4200. To use a different port:--port <number>- Specify a different port--openor-o- Automatically open the browser--host <hostname>- Specify the host (default: localhost)--ssl- Serve using HTTPS
Common Issues and Troubleshooting
Port 4200 is already in use
Port 4200 is already in use
If you see an error that port 4200 is already in use:Option 1: Kill the existing processOption 2: Use a different port
Backend connection errors
Backend connection errors
If you see errors related to HTTP requests or authentication:
-
Verify the backend is running:
- Check CORS configuration on the backend
- Verify the API endpoints match what the frontend expects
- Check the browser console for specific error messages
Compilation errors after pulling changes
Compilation errors after pulling changes
If you encounter compilation errors after pulling new changes:
-
Clear the Angular cache:
-
Reinstall dependencies:
- Restart the development server
Slow compilation or hot reload
Slow compilation or hot reload
If you experience slow build times:
- Close unnecessary applications to free up system resources
- Increase Node.js memory limit:
- Consider using
--pollif file watching isn’t working:
