I have Environment-specific variables stored in the spinnaker manifest. I want to replace some variables in the angular app when deployed to dev, qa, and prod environments. How to change my code to achieve this? I am doing this because I do not want to store those variables values in the source code as it is not safe.
I tried to find them my own but failed and I am desperate.
A common approach to managing environment variables in many projects is to use
.env
files. Here is how you can do this for your Angular application:Creating
.env
Files:.env
file for each environment. For example:.env.dev
,.env.qa
and.env.prod
.Integrating with Angular:
.env
file..env
file based on the target environment.Build Scripts:
package.json
, define build scripts for each environment:Accessing Variables in Code:
environment.ts
files to access these variables. For example:environment
file and accessenvironment.apiUrl
.Security:
.env
files to your.gitignore
to ensure they are not pushed to the repository. This is crucial for keeping secrets and sensitive variables out of version control.Hope this helps you configure and manage your environment variables effectively for different environments in your Angular application!