Environment Variables Flashcards
What is an environment variable and what is its purpose in software development?
An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. They are used in software development to manage configurable values separate from code, such as API keys, database connections, or operational settings.
How can you access environment variables in projects using modern bundlers like Vite?
In Vite, you can access environment variables by prefixing them with VITE_ in your .env file, and then using import.meta.env.VITE_YOUR_VARIABLE in your JavaScript to access the value.
How and when should you define a new environment variable for a project?
Define a new environment variable when you need to manage values that vary between environments (development, testing, production) or need to be kept secure. Set them in your environment or .env file before your application starts, and ensure they are documented for other developers.
How are environment variables used when deploying applications in containers?
When deploying with containers, you can specify environment variables in the container’s configuration file (like Docker’s Dockerfile or docker-compose.yml). These variables can be passed into the container at runtime, allowing configuration changes without modifying the container image.
What is a feature flag?
A feature flag is a technique to enable or disable functionality of an application without deploying new code.
When to use a feature flag?
Use feature flags when you want to test new features safely in production, provide features to specific users, or maintain multiple feature variants in live environments.