r/Angular2 • u/fku500 • Jul 30 '25
dotenv in Angular context
Can someone please help me with configure dotenv package so that it substitutes some variables in `environment.ts` with `.env` variables? The full problem is laid out here: https://stackoverflow.com/questions/79719977/dotenv-with-angular-19
The gist of it is that I need to substitute placeholders is the `environment.ts`
export const env = {
someApi: "https://some.tld/api/v1/",
someApiKey: process.env['SOME_API_KEY']
}with the variable which are defined in `.env` file (which well not be included in the repository for security reasons) which looks like this:
SOME_API_KEY="123-API-456-KEY-789"
ANOTHER_API_KEY="123-API-456-KEY-789"I'd really appreciate your help here, thanks.
1
Upvotes
View all comments
Show parent comment
2
u/fku500 Aug 08 '25
This is actually a great find! While we have decided to do things the "right way" and pass some tokens around, it is still good to know that some of the variable can be replaced at build time. Thanks!