Blog>
Snippets

Environment-Specific Configuration

Explain how to manage different environments in an Angular application using Angular CLI's environment file generation.
// environment.ts
export const environment = {
  production: false,
  apiUrl: 'http://localhost:3000/api'
};
This is the default environment configuration file for development. It sets production to false and includes a local API URL.
// environment.prod.ts
export const environment = {
  production: true,
  apiUrl: 'https://prod.example.com/api'
};
This is the environment configuration for the production environment. It sets production to true and includes the production API URL.
import { environment } from './environments/environment';

console.log(environment.apiUrl);
This code imports the correct environment configuration based on the current environment and logs the API URL to the console.
ng build --prod
Angular CLI command to build the application for production, using the environment.prod.ts configuration.