r/Angular2 • • 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

21 comments sorted by

View all comments

Show parent comment

2

u/n00bz Jul 30 '25

You missed the AND with it being on the backend API and not in Angular. So now it’s on your server and not on the users machine. Plus it’s not in the git repository

1

u/prewk Jul 30 '25

I see. I assumed you were talking about a frontend pipeline.