Core Concepts
Environment Variables
Managing environment variables in Webiny projects.
Overview
Environment variables in Webiny are optional for most scenarios. When needed, they follow a prefix-based system that ensures variables are only available to the appropriate application. This prevents accidental exposure of sensitive data between applications.
Application Prefixes
Webiny uses prefixes to route variables to specific applications:
WEBINY_ADMIN_- Variables for the Admin applicationWEBINY_API_- Variables for the API application- No prefix - Available to all applications (use sparingly)
Usage
Setting Variables
Create a .env file in your project root:
Accessing Variables
In your extensions, access variables through process.env:
TypeScript Support
Add type definitions for your environment variables:
Environment-Specific Variables
Local Development
Variables in .env are loaded during:
yarn webiny watch adminyarn webiny watch apiyarn webiny deploy
Deployed Environments
For deployed environments, set variables before deployment:
CI/CD Integration
In CI/CD pipelines, set environment variables:
Best Practices
Security
- Never commit
.env- Add to.gitignore - Use prefixes - Isolate sensitive data by application
- Rotate secrets - Change production secrets regularly
- Minimal exposure - Only set variables that are needed
Documentation
Create .env.example for team reference:
Variable Naming
Follow consistent naming conventions:
Common Use Cases
Third-Party Services
Feature Flags
API Configuration
Debugging
Verify Variables
Check loaded variables during development:
Common Issues
Variable not available:
- Check prefix matches application (ADMIN vs API)
- Ensure
.envfile is in project root - Restart watch command after changing
.env - Verify no typos in variable names
Variables in wrong application:
- Admin extensions can’t access
WEBINY_API_variables - API extensions can’t access
WEBINY_ADMIN_variables - Use correct prefix for the target application
Infrastructure Variables
For infrastructure extensions, access variables directly:
Migration From V5
If upgrading from Webiny v5:
- Add prefixes to existing variables
- Update code to use prefixed names
- Test thoroughly in development