Page:
Secrets and .env
Pages
API SMHI
API TimeEdit
Accessibility Testing
Api documentation
Bat/Ps
Branch Creation
C# Coding Convention
CSS Coding Convention
Coding Conventions
Creating new databases
Dapper
Documentation for service endpoints
Documentation of useTemperature and mock sensor
Energy endpoints
Environment
Evaluation react-grid-layout
Evaluation Localization
Evaluation Password hashing
Evaluation Testing framework
Evaluation of Logging Frameworks
Formatter
Frontend model
Generic Diagram for Sensor data flow
Home
How to- Creating Databases in Docker
Implementing different Styles
Implementing new Mockup sensors
Implementing new Views
Installation script documentation
Installation
Issues
JSON Coding Convention
Jest Testing
Layout endpoints
Linux
Localization
Login endpoints
Mac
Middleware model
Mock API Ceation Guidelines
Mockup models
Model Tools and Standards
Parking endpoints
React/JavaScript Coding Convention
React
Reviews
Room booking endpoints
SQL Coding Convention
Scheduled Database tasks
Scripting Coding Convention
Secrets and .env
Server Access
Server-Deployment
Service/API models
System models
System requirements
Temperature endpoints
Testing API with Bruno
Testing Architecture
Testing frontend for Mobile devices
Testing frontend with Playwright
Testing methodology
Västtrafik API
Webpage Design
Windows
pg_cron and scheduled database jobs
xUnit Testing
No results
12
Secrets and .env
Tim Svensson edited this page 2026-04-27 10:26:28 +00:00
.env file
- An .env file is used to store sensitive data e.g credentials using environment variables instead of hardcoding them directly in the code.
Why use .env file
We use an .env file to separate configuration values from the code.
- This keeps sensitive data out of the code.
- It improves security since the values are not pushed to the repository.
- It allows for flexibility as values can be updated without changing the code.
When to use .env file
- An .env file can be used when working with credentials or other sensitive data.
- We currently use it for MQTT and all Postgres databases.
- It's also useful when values need to change between different environments, e.g when each developer uses their own local configuration.
How it works
- Values are stored in .env file.
- The compose.yaml file uses environment variable references that are replaced with values from the .env file. Docker Compose documentation
- The services get the values from the environment using Environment.GetEnvironmentVariable.
It is extremly important that the .env is never included in a commit! Do NOT remove it from the .gitignore!
Create .env file
The .env file is generated automatically by the installation scripts (README) and is placed in the same directory as the compose file. The .env file will only be generated if it doesn't currently exist, so if new values are added by another branch you will need to delete it manually to receive new fields.
An example of how the .env file might look like:
DATABASE_USER=120153063346022930723500
DATABASE_PASSWORD=2965047416668206777197
Docker Compose
The variables are set in compose.yaml and used by the services:
environment:
DATABASE_USER: ${DATABASE_USER}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
Using environment variables
Values are read using Environment.GetEnvironmentVariable:
Environment.GetEnvironmentVariable("DATABASE_USER");
Environment.GetEnvironmentVariable("DATABASE_PASSWORD");
1. Setup
2. Standards
- Coding Conventions
- Issues
- Branch creation
- Reviews
- Implementation Standards
- [WIP] Creating new databases
- Localization
3. Models and Diagrams
4. Testing
5. Documentation
- Documentation for service endpoints
- API documentation
- Webpage Design
- Secrets and .env
- Evaluations
- Installation and Rebuild script documentation
6. Guides and How-to's
7. Micro Service Mockup Api
- Guidelines Mircro Service Mockup
- Documentation of useTemperature/useTemperatureTimeSeries mockup sensor