Sobes.tech
Junior — Middle

Explain what environment variables are and how they are used in applications.

sobes.tech AI

Answer from AI

Environment variables are key-value pairs set in the operating system and accessible to the application during its runtime. They are used to store configuration data such as database settings, API keys, resource paths, and other parameters that may vary across different environments (development, testing, production).

Using environment variables allows sensitive data not to be stored in code and makes it easy to change configuration without recompiling the application. For example, in Node.js, you can access an environment variable like this:

const dbPassword = process.env.DB_PASSWORD;

In Linux, an environment variable can be set with the command:

export DB_PASSWORD=mysecretpassword

Thus, environment variables provide flexibility and security when configuring applications.