0

I want different .env files to be loaded on the production server and on the staging server. What approaches are there for this?

Note: Currently i use the dotenv package.

Max Pattern
  • 1,430
  • 7
  • 18
  • 1
    How do you load `.env` files now? – Konrad Nov 07 '22 at 21:36
  • @KonradLinkowski with the `.dotenv` package – Max Pattern Nov 07 '22 at 21:37
  • 1
    Does this answer your question? [Toggle between multiple .env files like .env.development with node.js](https://stackoverflow.com/questions/55406055/toggle-between-multiple-env-files-like-env-development-with-node-js) – Konrad Nov 07 '22 at 21:38
  • @KonradLinkowski Thank you for the useful link. But I don't understand how the application should know that it is on the production server or on the staging or local. If I have three .env files: `.env.local, .env.production, .env.staging`. I seem to have a problem understanding this. – Max Pattern Nov 07 '22 at 21:45
  • 1
    You should set `NODE_ENV` variable – Konrad Nov 07 '22 at 21:47
  • @KonradLinkowski I think now I've realised it. I can only have one .env in the node project. this is not shared in the repository. That means I have to manually put it on the server with the right credentials to stage. Correct? Then I have access to the .env and the set vars. – Max Pattern Nov 07 '22 at 21:50
  • You usually don't store environment variables on the servicer inside an `.env` file. – Konrad Nov 07 '22 at 22:04
  • @KonradLinkowski okay? Where then? – Max Pattern Nov 07 '22 at 23:27

0 Answers0