Environment Configuration
Relevant source files
The following files were used as context for generating this wiki page:
Environment configuration manages the settings and variables required to run the marketplace application across different stages, such as development and production. The system uses a combination of Angular environment files for the frontend and environment-specific command execution for the backend to ensure the software behaves correctly in each deployment context.
The configuration defines critical parameters including API endpoints, internationalization settings, and build-time flags. This separation allows the application to point to local development services during testing while switching to production infrastructure during deployment without changing the core application logic.
Frontend Environment Management
The Angular frontend manages environments through dedicated TypeScript files located in the src/environments/ directory. The project defines two primary configurations: a default development environment and a production environment.
Build-Time File Replacement
The Angular CLI swaps the environment files during the build process based on the target configuration. When you execute a production build, the build tool replaces the standard environment.ts with environment.prod.ts.
The diagram shows how the build process replaces environment files based on the project configuration.
Sources: marketplace-frontend/angular.json:33-38, marketplace-frontend/src/environments/environment.ts:1-6
Frontend Configuration Properties
Both environment files export a constant named environment containing the following properties:
| Property | Type | Description |
|---|---|---|
production | boolean | Indicates if the application is running in production mode. |
backendServerEndpoint | string | The URL of the backend API server. |
defaultLocale | string | The default language code for internationalization. |
locales | string[] | A list of supported language codes. |
Sources: marketplace-frontend/src/environments/environment.ts:8-13, marketplace-frontend/src/environments/environment.prod.ts:1-6
Backend Environment Management
The NestJS backend manages environment variables using the env-cmd utility. This allows the server to load specific variables from external files depending on the execution script used.
Execution Scripts
The backend defines different start scripts in its configuration to target specific environments:
- Development: Uses
local.envto configure the server for local testing. - Production: Uses
production.envto configure the server for live deployment.
The diagram illustrates how different scripts trigger environment-specific variable loading.
Sources: marketplace-backend/app/package.json:13-16
Integration with Application Modules
The application modules consume the environment configuration to initialize third-party libraries and internal services. For example, the AppModule uses the environment.defaultLocale to set up the translation service.
TranslateModule.forRoot({
defaultLanguage: environment.defaultLocale,
useDefaultLang: true,
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient],
},
// ...
})
Sources: marketplace-frontend/src/app/app.module.ts:43-52
Summary of Environment Settings
The marketplace application maintains consistency between frontend and backend environments through the following configuration mapping:
| Environment | Frontend Script | Backend Script | Frontend API Endpoint |
|---|---|---|---|
| Local/Dev | npm start | npm run start:dev | http://as.localhost.com:4000 |
| Production | ng build --prod | npm run start:prod | http://as.localhost.com:4000 |
Sources: marketplace-frontend/package.json:5, marketplace-backend/app/package.json:14-16, marketplace-frontend/src/environments/environment.ts:10
Environment configuration ensures that the marketplace application remains portable and maintainable. By isolating environment-specific data from the source code, the project supports a streamlined development lifecycle from local coding to production deployment.