# Vapor how to control environment variables for different environments

**URL:** <https://forums.swift.org/t/vapor-how-to-control-environment-variables-for-different-environments/68500>\
**Category:** Vapor\
**Tags:** testing, discussion\
**Created:** [November 16, 2023, 7:25pm UTC](https://forums.swift.org/t/vapor-how-to-control-environment-variables-for-different-environments/68500 "2023-11-16T19:25:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wheelius](https://avatars.discourse-cdn.com/v4/letter/w/e274bd/32.png) [@wheelius](https://forums.swift.org/u/wheelius)\
**Post date:** [November 16, 2023, 7:25pm UTC](https://forums.swift.org/t/vapor-how-to-control-environment-variables-for-different-environments/68500/1 "2023-11-16T19:25:06Z")

</div>

I'm pretty knew to Vapor (and server-side development as a whole) and was curious about the best practices / options there are for utilizing environment variables in testing?

Currently I use a .env file which allows me to use `Environment.get("My_Key")`, as well as a docker-compose file to dynamically load them using `environment: My_Key: ${value}`.

From my understanding this by default loads from the .env file. How can I have it load from different files for different environments such as .env.dev or .env.test? Or is there another (better) practice for handling secrets?

For more context these secrets are for Azure hosted services such as Azure Blob Containers and Azure Database for PostgreSQL.

---

<div class="post-metadata">

**Author:** ![grahamburgsma](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grahamburgsma/32/5597_2.png) [@grahamburgsma](https://forums.swift.org/u/grahamburgsma)\
**Post date:** [November 16, 2023, 7:28pm UTC](https://forums.swift.org/t/vapor-how-to-control-environment-variables-for-different-environments/68500/2 "2023-11-16T19:28:01Z")

</div>

I believe the documentation answers all your questions: [Vapor: Basics → Environment](https://docs.vapor.codes/basics/environment/#env-dotenv)

---

<div class="post-metadata">

**Author:** ![wheelius](https://avatars.discourse-cdn.com/v4/letter/w/e274bd/32.png) [@wheelius](https://forums.swift.org/u/wheelius)\
**Post date:** [November 16, 2023, 7:36pm UTC](https://forums.swift.org/t/vapor-how-to-control-environment-variables-for-different-environments/68500/3 "2023-11-16T19:36:02Z")

</div>

Ah I missed the section talking about the dotenv naming 🤦‍♂️ Thank you for the quick response.
