Environment Variables
Configure your app with environment variables. Your AI assistant handles the setup — just tell it what your app needs.
Your AI Assistant Manages This
Environment variables are defined in your nexlayer.yaml file under the vars section. Just tell your AI assistant what environment variables your app needs, and it will configure them correctly.
Basic Usage
Environment variables are defined per-pod in your nexlayer.yaml:
application:
name: my-app
pods:
- name: api
image: myuser/api:latest
path: /api
servicePorts: [3000]
vars:
NODE_ENV: production
LOG_LEVEL: info
API_KEY: your-api-keyConnecting Services
The most common use of environment variables is connecting your services together. Use Nexlayer's internal DNS to reference other pods:
pods:
- name: postgres
image: postgres:15
servicePorts: [5432]
vars:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: secretpassword
POSTGRES_DB: myapp
- name: api
image: myuser/api:latest
servicePorts: [3000]
vars:
# Reference postgres using internal DNS
DATABASE_URL: postgresql://postgres:secretpassword@postgres.pod:5432/myappFormat: <pod-name>.pod:<port>
Common Patterns
Database Connections
# PostgreSQL
DATABASE_URL: postgresql://user:pass@postgres.pod:5432/mydb
# MySQL
DATABASE_URL: mysql://user:pass@mysql.pod:3306/mydb
# MongoDB
MONGODB_URI: mongodb://user:pass@mongo.pod:27017/mydb
# Redis
REDIS_URL: redis://redis.pod:6379API Connections
# Internal API
API_URL: http://api.pod:3000
# Frontend to Backend
NEXT_PUBLIC_API_URL: http://backend.pod:8080External Services
# Third-party APIs
STRIPE_SECRET_KEY: sk_live_...
OPENAI_API_KEY: sk-...
SENDGRID_API_KEY: SG...
# OAuth
GITHUB_CLIENT_ID: ...
GITHUB_CLIENT_SECRET: ...Security Note
Environment variables in nexlayer.yaml are stored securely and injected at runtime. However, avoid committing sensitive values to version control.
Tip: Tell your AI assistant "don't commit sensitive environment variables" and it will help you manage secrets safely.
Framework-Specific Notes
Next.js
For client-side variables, prefix with NEXT_PUBLIC_:
vars:
# Server-side only
DATABASE_URL: postgresql://...
# Available in browser
NEXT_PUBLIC_API_URL: https://api.example.comVite / React
For client-side variables, prefix with VITE_:
vars:
VITE_API_URL: https://api.example.com