Environment Variables

What is it?

Environment variables are dynamic configuration values stored outside your application code that control how the application behaves in different environments. They are essential for storing sensitive data like API keys, database passwords, and third-party service credentials, as well as environment-specific settings that differ between development, staging, and production without changing code.

Practical example

Your application connects to different databases in development and production. Instead of hardcoding credentials, you create a .env file (added to .gitignore so it is never committed) with DATABASE_URL containing your local connection string. In production, you configure the same variable through your hosting platform. Your code reads process.env.DATABASE_URL and works seamlessly in both environments without any code changes.

Test your knowledge

Why use environment variables for sensitive data?

Ask Lex
Lex knows the context of this term and can give targeted explanations, examples, and extra context.
Tip: Lex replies briefly in the widget. For more detail, go to full screen mode.

Quick links