Core Concepts
Environment Variables
Managing environment variables in Webiny projects.
WHAT YOU'LL LEARN
- How to use environment variables in Webiny - Application-specific variable prefixes - Best practices for sensitive data
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
Usage
Setting Variables
Create a .env file in your project root:
.env
Accessing Variables
In your extensions, access variables through process.env:
extensions/MyApiExtension.ts
extensions/MyAdminExtension.tsx
TypeScript Support
Add type definitions for your environment variables:
webiny-env.d.ts
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:
.env.example
Variable Naming
Follow consistent naming conventions: